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

[CareerCup] 【第三轮】6.30-7.6 CareerCup 3.5

🔗
wilbert 2014-7-7 00:05:30 | 只看该作者
全局:
【解题思路】
enqueue: push to the pushStack
dequeue: if popStack is empty, (1) if pushStack is empty:EXCEPTION, (2) pop pushStack and push to popStack. pop one element from popStack.
【时间复杂度】
enqueue: O(1)
dequeue: O(N)
【空间复杂度】
O(N)
【gist link】
https://gist.github.com/iwilbert/6c6744b3ad423ad6a436
回复

使用道具 举报

🔗
林微熙 2014-7-7 04:08:17 | 只看该作者
全局:
本帖最后由 林微熙 于 2014-7-6 13:10 编辑

【解题思路】use 2 stacks , one for push, one for pop
【时间复杂度】o(n)
【空间复杂度】o(n)
【gist link】https://gist.github.com/hilda8519/50757a448bbfd7463a64
回复

使用道具 举报

🔗
锦木千束 2014-7-7 23:46:22 | 只看该作者
全局:
【解题思路】
using two stacks stackIn and stackOut to push/pop elements
push: stackIn.push
pop: if stackOut is empty, move all elements of stackIn into stackOut
size: stackIn.size + stackOut.size
back: stackIn.peek, if stackIn is empty, move all elements of stackOut into stackIn
front: stack.Out.peek, if stackOut is empty, move all elements of stackIn into stackOut
【时间复杂度】O(1) or O(n) (if the stack is empty)
【空间复杂度】O(N)
https://gist.github.com/weazord/f231350faa96658a1016
回复

使用道具 举报

🔗
锦木千束 2014-7-7 23:47:52 | 只看该作者
全局:
https://gist.github.com/weazord/f231350faa96658a1016

打了这么多字突然回复框内容全消失了, 不打了...
回复

使用道具 举报

🔗
tonygxxx1212 2014-7-8 03:08:16 | 只看该作者
全局:
【解题思路】data_stack 和 buffer, pop和push来改变顺序,模拟FIFO
【时间复杂度】O(1) for enque; O(n) for deque()
【gist link】https://gist.github.com/xun-gong/5c1fe614008cdb762a8b
回复

使用道具 举报

🔗
jason51122 2014-7-8 11:38:21 | 只看该作者
全局:
【解题思路】Create 2 stacks: one for add() and one for remove().
【时间复杂度】O(1) for add() and O(N) for remove().
【空间复杂度】O(N)
【gist link】https://gist.github.com/jason51122/ef61390dee4871050cda
回复

使用道具 举报

全局:
【解题思路】
One stack for enqueue, one stack for dequeue
move elements to the other stack only when needed

【时间复杂度】
O(1) for best cases, O(n) for worst cases

【空间复杂度】
O(n)


【gist link】
https://gist.github.com/happyWinner/fc453f95338657706d05




评分

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

查看全部评分

回复

使用道具 举报

🔗
renli3000 2014-7-14 02:09:17 | 只看该作者
全局:
【解题思路】
One stack for enqueue
The other stack for dequeue
Move all elements from one to the other to reverse the sequence if necessary
【时间复杂度】
O(N) in worst case

【空间复杂度】
O(n)

【gist link】
https://gist.github.com/Noahsark/62eb271bb42ff4d05c96
回复

使用道具 举报

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

本版积分规则

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