12
返回列表 发新帖
楼主: wrj5518
跳转到指定楼层
上一主题 下一主题
收起左侧

[CareerCup] 【第三轮】7.7-7.13 CareerCup 3.7

🔗
jason51122 2014-7-9 12:55:19 | 只看该作者
全局:
donnice 发表于 2014-7-9 01:17
【解题思路】
用两个LinkedList
【时间复杂度】

Please do not use characters to represent dog and cat. It's better to create 2 classes. Thanks.
回复

使用道具 举报

🔗
donnice 2014-7-9 19:15:56 | 只看该作者
全局:
jason51122 发表于 2014-7-9 12:55
Please do not use characters to represent dog and cat. It's better to create 2 classes. Thanks.

昨天没时间了…没必要写两个 class啊,两个list就够了,分别给猫狗起名,dequeue时输入名字,contains(String name)而已,小技术
回复

使用道具 举报

全局:
【解题思路】
Use two linked list, one for cats, one for dogs
add timestamps to cats and dogs

【时间复杂度】
O(1)


【空间复杂度】
O(n)


【gist link】
https://gist.github.com/happyWinner/8a155f4feea9cf27df4d

评分

参与人数 1大米 +2 收起 理由
kimiflasky + 2 回答的很好!

查看全部评分

回复

使用道具 举报

🔗
jyh橘子 2014-7-12 08:36:40 | 只看该作者
全局:
【解题思路】
Use two linked lists for cats and dogs respectively;  use an extra attribute for animal " order " to record the time they enter the shelter.
【时间复杂度】O(1)
【空间复杂度】O(n)
【gist link】https://gist.github.com/jyhjuzi/de9393fb070b4061d34e
回复

使用道具 举报

🔗
兰橘清檬 2014-7-13 01:05:26 | 只看该作者
全局:
【解题思路】
Maintain two separate queues for dogs and cats.

【时间复杂度】
O(1)

【空间复杂度】
O(n)

【gist link】
https://gist.github.com/JoyceeLee/d530c6ba41dd9c16abcc
回复

使用道具 举报

🔗
wilbert 2014-7-13 07:02:58 | 只看该作者
全局:
【解题思路】
Create two Queue Cats and Dogs, the class Cat and Dog inherits from Animal, use id to indicate the arrival time
【时间复杂度】
O(1)
【空间复杂度】
O(N)
【gist link】
https://gist.github.com/iwilbert/896f3f2b5b67a0ee3340
回复

使用道具 举报

🔗
renli3000 2014-7-14 04:17:33 | 只看该作者
全局:
【解题思路】
开始没看见“use the built-in LinkedList data structure” 就自己写了个queue, 直接用java.util.LinkedList<E> 也是大同小异
这题主要考design,用继承和多态区分dog和cat就可以了,至于queue,可以用generic也可以用多太写
【时间复杂度】
O(1)
【空间复杂度】
O(N)
【gist link】
https://gist.github.com/Noahsark/9974157a98091e89773e
回复

使用道具 举报

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

本版积分规则

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