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

[CareerCup] [第二轮] 3/4-3/10 CareerCup 3.6

🔗
lty900301 2013-3-4 15:12:48 | 只看该作者
全局:
EchoMemory 发表于 2013-3-4 12:34
ok..my solution is based in the description of the problem, where "You may use additional stacks"  ...

one additional stack: other, is enough. This additional stack holds all the sorted items.
while(!input.isEmpty)
    Use tmp to store the input.pop
    while(!other.isEmpty & other.peek is greater then tmp)
        input.push(other.pop)
    other.push(tmp)
return other
回复

使用道具 举报

🔗
EchoMemory 2013-3-4 15:27:37 | 只看该作者
全局:
ryancooper 发表于 2013-3-4 14:21
If I can be allowed to use one additional variable, then I can reduce two additional stacks to jus ...

Yes, I understand your solution. Thx for reminder, I edited again.
回复

使用道具 举报

🔗
EchoMemory 2013-3-4 15:29:11 | 只看该作者
全局:
lty900301 发表于 2013-3-4 15:12
one additional stack: other, is enough. This additional stack holds all the sorted items.
while( ...

I see...that's right, too.
回复

使用道具 举报

🔗
leonsu777 2013-3-5 06:42:59 | 只看该作者
全局:
https://github.com/longwei/Algo/ ... h3/SortedStack.java
Note:
1. pop arbitrary element from Stack1, and push into Stack2, and then pop S2 back to S1. the order is stable. which give us a double-linked list data structure.
2. as a result, we could pop unsorted stack, and insert it into the right position in the sorted stack
回复

使用道具 举报

🔗
weep_willow 2013-3-6 06:39:15 | 只看该作者
全局:
用了两个stack, 思想跟答案一致
c++ implementation

https://github.com/StanleyLee/CareerCup/blob/master/3_6.cpp
回复

使用道具 举报

🔗
cjsp 2013-3-10 10:39:14 | 只看该作者
全局:
https://gist.github.com/flatlight/5126811
在另一个栈中做插入排序
回复

使用道具 举报

🔗
ThunderXu 2013-3-10 12:22:21 | 只看该作者
全局:
https://gist.github.com/ThunderXu/5127102
Take the idea from QuickSort, use recursion to solve the problem, when there are only 2 elements, it is easy to sort them only by stacks. One thing to pay attention to is a stack can not be copied to another just by poping it and pushing another, in that situation the elements of these two stacks will be reversed.
回复

使用道具 举报

🔗
reeeelan 2013-3-12 00:58:55 | 只看该作者
全局:
这个题对时间复杂度有要求吗? 我能想到的最好办法n平方可以解决,三个stack的办法
回复

使用道具 举报

全局:
https://github.com/1094401996/Ca ... AscendingStack.java

两个堆栈来回倒。。。。。
回复

使用道具 举报

🔗
grassgigi 2013-3-15 10:35:44 | 只看该作者
全局:
回复

使用道具 举报

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

本版积分规则

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