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

[CareerCup] [第二轮] 2/25-3/3 CareerCup 2.4

🔗
champoier 2013-2-27 05:45:23 | 只看该作者
全局:
qsort思想,2个指针,第二个指针一直扫,小于等于pivot跟第一个指针swap.
https://gist.github.com/skxie/d0a11009756fe37d4720
回复

使用道具 举报

🔗
 楼主| Fanyare 2013-2-28 03:22:11 | 只看该作者
全局:
https://github.com/quantumrose/C ... /2.4.Partition.java
create two linked lists to hold node less than x and nodes greater than or equal to x, then merge
回复

使用道具 举报

🔗
lazyGoose 2013-2-28 09:27:37 | 只看该作者
全局:
https://gist.github.com/lazyGoose/5053421

create two LinkNode l1, l2,  iterate the head, put the smaller element into l1 and larger ones into l2. Then, merge l1 and l2, return l1 + l2
回复

使用道具 举报

🔗
weep_willow 2013-2-28 10:58:34 | 只看该作者
全局:
Solution: Use the idea of qsort, two pointers, to traverse the list:
1. start location for the first pointer: the first pointer stops once a value if found to be greater than x;
2. start location for the second pointer: starts from the node right after the first pointer
3. then the second pointer starts to traverse the rest node. if value less than x is found, then swap the two nodes' value information and move the first pointer to the next.
Time complexity: O(n); Space complexity: O(1)

c/c++ 实现

https://github.com/StanleyLee/CareerCup/blob/master/2_4.cpp
回复

使用道具 举报

🔗
moophis 2013-2-28 13:56:14 | 只看该作者
全局:
Use a pointer called middle to divide the list into three parts: (<x) nodes, (=x) nodes and (>x) nodes. For each iteration, move current nodes to the right place. This way I have to handle more edge conditions.
https://github.com/moophis/careercup/blob/master/2.2-4.cpp#L177
回复

使用道具 举报

🔗
qeroqero 2013-2-28 23:47:24 | 只看该作者
全局:
本帖最后由 qeroqero 于 2013-2-28 23:48 编辑
Fanyare 发表于 2013-2-28 03:22
https://github.com/quantumrose/CareerCup/blob/master/2.4.Partition.java
create two linked lists to  ...

先用一个指针读出x VALUE,再从头指针遍历,大于等于value X的移至linked list尾巴 就可以吧?

点评

make sure don't be trapped in infinite loop  发表于 2013-3-1 06:12
回复

使用道具 举报

🔗
leonsu777 2013-3-1 03:20:26 | 只看该作者
全局:
https://github.com/longwei/Algo/ ... /ch2/Partition.java
stable partition.
用qsort的办法很巧, 等下试一下
回复

使用道具 举报

🔗
ThunderXu 2013-3-2 11:56:16 | 只看该作者
全局:
https://gist.github.com/ThunderXu/5069631
iterate the list and remove elements to a new list if it < x, at last link this two lists.
回复

使用道具 举报

🔗
cjsp 2013-3-2 15:04:57 | 只看该作者
全局:
https://gist.github.com/flatlight/5069987
use two linked list to hold the nodes in two partitions, then concatenate these two
回复

使用道具 举报

🔗
Kimurate 2013-3-3 09:42:16 | 只看该作者
全局:
* Method: Get the smaller elements and hold them in a linked list,
* link the original list after the new list.
C language:
https://gist.github.com/hukun01/5074100
回复

使用道具 举报

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

本版积分规则

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