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

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

🔗
pud 2014-7-3 05:49:46 | 只看该作者
全局:
【解题思路】
create another stack to record the minimum element in the stack for every push.  pop both stacks.
【时间复杂度】
O(1)
【空间复杂度】
O(n)
【gist link】
https://gist.github.com/yokiy/7ab19f4b78de60a32eb5
回复

使用道具 举报

🔗
jyh橘子 2014-7-3 06:51:09 | 只看该作者
全局:
【解题思路】
use an extra stack to store the min values.  push an element to the extra stack if the min changes;  Also pop the min value from the extra stack when it is popped from the primary stack;
【时间复杂度】
O(1)
【空间复杂度】
O(n)
【gist link】 https://gist.github.com/jyhjuzi/60c4cad863717bff7e04
回复

使用道具 举报

🔗
Neal 2014-7-3 11:03:29 | 只看该作者
全局:
【解题思路】Use another stack to keep min values
【时间复杂度】O(1)
【空间复杂度】O(n)
【gist link】https://gist.github.com/nealhu/9fd25a583db13d4e7647
回复

使用道具 举报

🔗
兰橘清檬 2014-7-3 11:13:25 | 只看该作者
全局:
【解题思路】
construct a new class to extend the class Stack with an inner Stack to record the mins
【时间复杂度】
O(1)
【空间复杂度】
O(n)
【gist link】
https://gist.github.com/JoyceeLee/9fdc6b744d63b0238b3a
回复

使用道具 举报

🔗
wilbert 2014-7-5 05:47:36 | 只看该作者
全局:
【解题思路】
use an extra array to track the min, but only push the val to this array if the val is smaller than the current min. when pop, if the value is equal to the current min, then update the min.
【时间复杂度】
Amortized O(1) for push and O(1) for pop and min
【空间复杂度】
O(N)
【gist link】
https://gist.github.com/iwilbert/5c62763ac77541d24e28
回复

使用道具 举报

🔗
nickmyself 2014-7-5 06:11:01 | 只看该作者
全局:
【解题思路】
Keep 2 stacks, one for original element, one for min element.
【时间复杂度】
pop(),push(),min()均为 O(1)
【空间复杂度】
O(n)
【gist link】
https://gist.github.com/nickmyself/1af9ebe0ed35c6a8f843
回复

使用道具 举报

🔗
jason51122 2014-7-6 08:58:14 | 只看该作者
全局:
【解题思路】User another stack to store the current min.
【时间复杂度】O(1)
【空间复杂度】O(N)
【gist link】https://gist.github.com/jason51122/60751e16fd55a162bf8b
回复

使用道具 举报

🔗
whiteflower 2014-7-6 09:56:21 | 只看该作者
全局:
【解题思路】construct a vector to store data and a minStack to store min
【时间复杂度】O(1)
【空间复杂度】O(N)
【gist link】https://gist.github.com/JoshuaTang/f973c01175c5093102e9
回复

使用道具 举报

全局:
【解题思路】
use an extra stack (let's call it minValue) to hold every new minimum, min() returns minValue.top().
push into minValue when new data is smaller than or equal to current minimum
pop from minValue if the popped-out value was current minimum
【时间复杂度】
O(1)
【空间复杂度】
O(N)
【gist link】
https://gist.github.com/734e0c5815394b7d1313
【test case】
Example in the solution:
input: 5->6->3->7->pop->pop
output: 5, 5, 3, 3, 3, 5
回复

使用道具 举报

🔗
林微熙 2014-7-7 03:03:21 | 只看该作者
全局:
【解题思路】
use 1 int single value(min value) as a menber of the stack.When minvalue is poped from the stack, update.
【时间复杂度】
o(1)
【空间复杂度】
o(n)
【gist link】https://gist.github.com/hilda8519/7963ed7fe23fdc513dfd
回复

使用道具 举报

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

本版积分规则

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