楼主: wrj5518
跳转到指定楼层
上一主题 下一主题
收起左侧

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

🔗
pud 2014-7-4 13:34:24 | 只看该作者
全局:
【解题思路】  list 存放stacks,如果一个stack满了就push到新的stack中, pop后如果stack空了,就删除当前stack
【时间复杂度】
  O(1)
【空间复杂度】
  O(n)
【gist link】https://gist.github.com/yokiy/f8bd12d4622703486f68
回复

使用道具 举报

🔗
锦木千束 2014-7-4 18:17:22 | 只看该作者
全局:
【解题思路】
ues an ArrayList to store stacks
another ArrayList to store numbers of elements for the corresponding stack
add new stack when the number meet threshold
【时间复杂度】O(1)
【空间复杂度】O(N)
【gist link】https://gist.github.com/weazord/bbc47ea22f26d0a70a13
回复

使用道具 举报

🔗
wilbert 2014-7-6 07:51:12 | 只看该作者
全局:
【解题思路】
Use ArrayList of Stack, add new stack when the size of the last stack in the list meets the threshold. remove the stack in the list when the stack is empty.
【时间复杂度】
O(1)
【空间复杂度】
O(N)
【gist link】
https://gist.github.com/iwilbert/07aa98b1cccd43435eac
回复

使用道具 举报

🔗
jason51122 2014-7-6 14:47:57 | 只看该作者
全局:
【解题思路】Create an array of stacks and each stack is implemented by a doubly linked list.
【时间复杂度】O(1)
【空间复杂度】O(N)
【gist link】https://gist.github.com/jason51122/23f330b015529ee4ff68
回复

使用道具 举报

🔗
whiteflower 2014-7-6 19:43:43 | 只看该作者
全局:
【解题思路】// Construct a stack vector to store stacks. If one stack is full, create a new stack to store values.
【时间复杂度】O(1)
【空间复杂度】O(N)
【gist link】https://gist.github.com/JoshuaTang/550d3c4ee58ed36a630a

点评

//www.1point3acres.com/bbs/misc.php?mod=faq: 4.0
积分不够请看帮助 http://www.1point3acres.com/bbs/misc.php?mod=faq: 4
还不会写template…学习了!  发表于 2014-7-7 02:19
回复

使用道具 举报

全局:
【解题思路】
stack of stacks
FOLLOW UP:
vector of stacks
【时间复杂度】
O(1)
O(N) for popAt(), depends on sub-stack size
【空间复杂度】
O(N)
【gist link】
https://gist.github.com/1cfb941aafb1b6ab6a9a
回复

使用道具 举报

🔗
林微熙 2014-7-7 05:05:20 | 只看该作者
全局:
【解题思路】
【时间复杂度】
【空间复杂度】
【gist link】

先占一下这两天补
回复

使用道具 举报

🔗
tonygxxx1212 2014-7-7 06:16:53 | 只看该作者
全局:
【解题思路】c++ 用了vector, 每个元素是一个stack. 一个stack满了,新建一个stack接着push_back()到vector; 反之如果最后一个stack空了就马上
                         pop_back()
                  FOLLOW UP:pop的部分很直接,有了index,找到vector对应的那个stack 进行pop()。 比较烦的是,若pop非最后一个stack,就要移动后面的
                  所有元素,我用了临时的一个stack来移动,这部分代码多一点。
【时间复杂度】
O(1) : pop(), push(int data)
O(n) : popAt(int index)
【空间复杂度】
O(1) : pop(), push(int data)
O(n) : popAt(int index)
【gist link】
https://gist.github.com/xun-gong/432e30aa9c8c4419095c
回复

使用道具 举报

全局:
【解题思路】】

/*
* Use an array to keep track of the stacks. When pushing, create a new stack if
* the latest stack exceeds the capacity. When popping, delete the current stack
* if it is empty.
*
* Follow Up: just pop from the target stack from the array. Allow the stacks to
* be empty. Need to discuss this with the interviewer.
*/
【时间复杂度】
O(1)
【空间复杂度】
O(n)
【gist link】
https://gist.github.com/XiaoxiaoLi/362fb2deac674eca3987
回复

使用道具 举报

全局:
【解题思路】
use an array to store every stack
popAt() need move elements from next stacks to previous stacks


【时间复杂度】
O(1) for pop, push
O(m) for popAt (m is the number of stacks)

【空间复杂度】
O(n) (n is the number of total elements)

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

评分

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

查看全部评分

回复

使用道具 举报

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

本版积分规则

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