📣 独立日限时特惠: VIP通行证立减$68
楼主: wrj5518
跳转到指定楼层
上一主题 下一主题
收起左侧

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

🔗
兰橘清檬 2014-7-3 16:46:30 | 只看该作者
全局:
【解题思路】
push and pop of two stacks, sort one element for one time
【时间复杂度】
O(n^2)
【空间复杂度】
O(n)
【gist link】
https://gist.github.com/JoyceeLee/d0deb8471e0a0897fe24
回复

使用道具 举报

🔗
jyh橘子 2014-7-4 07:05:35 | 只看该作者
全局:
【解题思路】
1. at most one extra stack;    insert method to sort
2. if more than one extra stacks are allowed, use merge sort

【时间复杂度】1. O(n^2)  2. O(nlgn)
【空间复杂度】1.O(n)       2.O(n)
【gist link】https://gist.github.com/jyhjuzi/d8ce4f37872a1e255329

点评

good  发表于 2014-7-7 05:01

评分

参与人数 1大米 +10 收起 理由
林微熙 + 10 感谢分享!

查看全部评分

回复

使用道具 举报

全局:

【解题思路】
// Variation of Insertion Sort by using an extra stack. Iterate through every item in the input stack
        // We need to find the right place to insert the item in the result stack
        // we need to pop every item that is larger than it and we can store them by pushing them in the input stack, and then we push the element in the result stack
【时间复杂度】
O(n^2)
【空间复杂度】
O(n)
【gist link】
https://gist.github.com/XiaoxiaoLi/34f1cdc635f1365a9f70
回复

使用道具 举报

🔗
whiteflower 2014-7-6 21:25:54 | 只看该作者
全局:
【解题思路】
Assign the top element to another variable, pop it and
compare with the elements in the other stack. If it is
larger, just push it into the stack. Otherwise, pop elements
from the stack and push into original stack until the
original element is larger.
【时间复杂度】O(N^2)
【空间复杂度】O(N)
【gist link】https://gist.github.com/JoshuaTang/269d132360db2047c50e
回复

使用道具 举报

🔗
bitcpf 2014-7-6 21:54:04 | 只看该作者
全局:
【解题思路】Use another stack to reverse the source stack, when pop and push find the match value
【时间复杂度】O(n^2)
【空间复杂度】O(n)
【gist link】https://gist.github.com/bitcpf/ae426595e81cfcc832a8
回复

使用道具 举报

🔗
donnice 2014-7-7 02:50:25 | 只看该作者
全局:
【解题思路】用一个临时变量来记录stack里的最大值,将该值赋进信的stack,以此类推
【时间复杂度】O(n^2)
【空间复杂度】O(n)
【gist】
https://github.com/donnice/donnice/blob/master/Q3_6
【Test】
代码里自带
回复

使用道具 举报

🔗
wilbert 2014-7-7 03:43:50 | 只看该作者
全局:
【解题思路】
use temp stack to store the sorted elements, pop element from the original stack and insert to the temp stack
【时间复杂度】
O(N^2)
【空间复杂度】
O(N)
【gist link】
https://gist.github.com/iwilbert/02b8f9a6206c7739601c
回复

使用道具 举报

🔗
林微熙 2014-7-7 05:01:34 | 只看该作者
全局:
【解题思路】use 2 stack for push and pop, sort one for each time
【时间复杂度】o(n^2)
【空间复杂度】o(n)
【gist link】https://gist.github.com/hilda8519/faf7ac0aa630fff10216

回复

使用道具 举报

🔗
pud 2014-7-7 05:44:42 | 只看该作者
全局:
【解题思路】
pop element in the original stack to temp, compare temp with sorting stack, push larger element in sorting stack back to the original stack.
【时间复杂度】
O(N^2)
【空间复杂度】
O(N)
【gist link】https://gist.github.com/yokiy/9cb9c81a0b80be6e1b5e
回复

使用道具 举报

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

本版积分规则

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