查看: 1953| 回复: 1
跳转到指定楼层
上一主题 下一主题
收起左侧

[CareerCup] 【第四轮】6.28 - 7.4 Career Cup 3.7

全局:

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
本帖最后由 tailofjune 于 2015-6-28 22:47 编辑

写在前面:
首先十分抱歉,由于我记错了开始时间,今天的题目现在才贴出来.(本来当时想的是一周从周日开始算,后来记成周一了,汗- -b)
总之,今天刷题活动就正式开始了.报名的没报名的都欢迎参加,具体形式在直播帖中有.
祝大家都拿到满意的offer.




3.7 An animal shelter holds only dogs and cats, and operates on a strictly "first in, first out" basis.
People must adopt either the "oldest" (based on arrival time) of all animals at the shelter, or they can select whether they would prefer a dog or a cat (and will receive the oldest animal of that type). They cannot select which specific animal they would like.
Create the data structures to maintain this system and implement operations such as enqueue, dequeueAny, dequeueDog and dequeueCat.You may use the built-in LinkedList data structure.
                                

                        
               

请参加活动的童鞋跟帖回复自己的解法,回复请参考以下格式:

【解题思路】
【时间复杂度】
【空间复杂度】
【gist link】
【test case】(optional,如果觉得比较好,欢迎贴出来分享)

Notice:
1、记得在程序注释中表明自己算法的时间、空间复杂度
2、代码难懂之处加注释
3、每道题目有对应的帖子,除了贴解法,欢迎探讨各种follow up questions,集思广益
4、任何未尽之处,欢迎回报名帖提问,我会进一步作出修改



上一篇:请教前端学习和面试
下一篇:【第四轮】6.28 - 7.4 Career Cup 4.1
全局:
【解题思路】这题略偏design, 由于Java OO的东西有点儿遗忘, 于是参考了下java相关资料。首先时间戳timestamp用int来代替, 时间戳小的表示older. 使用LinkedList实现的2个Queue来模拟dogs和cats.dequeueAny的时候,要记得先判断当前是否有dogs或者cats已经为空。如果有为空的,则从不为空的dequeue, 如果都为空则进行比较哪个更加older就dequeue哪个。enqueue操作利用java的多态性,再引入一个字符串用于判断具体所指对象类型 (后来发现可以用instanceof)
【时间复杂度】O(1)
【空间复杂度】O(n)
【gist link】https://gist.github.com/zhangxin0804/80fac5b6893be3823766

评分

参与人数 1大米 +3 收起 理由
JamesJi + 3 坚持的不错,再接再厉!

查看全部评分

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表