123
返回列表 发新帖
楼主: wrj5518
跳转到指定楼层
上一主题 下一主题
收起左侧

[CareerCup] 【第三轮】6.23-6.29 CareerCup 2.4

🔗
jason51122 2014-6-29 05:40:05 | 只看该作者
全局:
【解题思路】Use 2 dummy nodes to partition and then link 2 parts together.
【时间复杂度】O(N)
【空间复杂度】O(1)
【gist link】https://gist.github.com/jason51122/8a0cf0419e646bfd1f7b
回复

使用道具 举报

🔗
jing0328 2014-6-29 15:14:38 | 只看该作者
全局:
【解题思路】traverse the list, if see a node with val <= partition, then move it to the front of the list
【时间复杂度】O(n)
【空间复杂度】O(1)
【gist link】https://gist.github.com/startupjing/b2bf5bd3ea3ee7a0e72f
回复

使用道具 举报

🔗
ivycheung1208 2014-6-30 07:58:00 | 只看该作者
全局:
【解题思路】
1. partition in place, use two iterators, one indicating boundary, one traversing the list as runner. if runner is smaller than x, insert it after bound, update bound, and remove it from original position.
2. use two temporary lists, holding smaller and larger parts respectively.
【时间复杂度】
O(N)
【空间复杂度】
1. O(1)
2. O(N)
【gist link】
https://gist.github.com/c569c1fdd39c0e91ad2e
回复

使用道具 举报

🔗
tonygxxx1212 2014-7-1 23:28:02 | 只看该作者
全局:
【解题思路】指针操作,分情况swap
【时间复杂度】O(n)
【空间复杂度】O(1)
https://gist.github.com/xun-gong/c851e00b91490b77e170
回复

使用道具 举报

🔗
guchang 2014-7-3 14:29:24 | 只看该作者
全局:
本帖最后由 guchang 于 2014-7-3 14:52 编辑

【解题思路】
使用一个双向列表,遍历链表,碰到比X小的,放到最前面去。
改进:
改成单向链表。
【时间复杂度】O(n)
【空间复杂度】O(1)
【gist link】https://gist.github.com/guchang/bff95e95ad201b335ed5
回复

使用道具 举报

🔗
whiteflower 2014-7-5 08:59:17 | 只看该作者
全局:
【解题思路】
traverse the list, put smaller element into beforeList,
put larger element into afterList, and at last append
afterList to beforeList
【时间复杂度】O(N)
【空间复杂度】O(N)
【gist link】https://gist.github.com/JoshuaTang/bdd2f058c2f3ad04d80a
回复

使用道具 举报

🔗
Tsien 2014-7-6 23:53:11 | 只看该作者
全局:
//【解题思路】
//建立两个链表,一个连接小于x的结点,另一个连接大于等于x的结点,最后合并
//两个链表
//【时间复杂度】
//O(n)
//【空间复杂度】
//O(1)
//【gist link】
https://gist.github.com/Tsien/2b657a0bc23f0ca63350
回复

使用道具 举报

全局:
【解题思路】
traverse the list and link the node to two differenet lists, one for nodes less than pivot, one for nodes greater than or equal to pivot
link the two list into one list

【时间复杂度】
O(n)

【空间复杂度】
O(1)

【gist link】
https://gist.github.com/happyWinner/8fbc805dd95161b4e219

评分

参与人数 1大米 +2 收起 理由
kimiflasky + 2 感谢分享!

查看全部评分

回复

使用道具 举报

🔗
sanguine 2014-12-29 08:34:45 | 只看该作者
全局:
Solution3
Idea: modify beyond the original linkedList, just like the partition method in qSort algorithm

Notice: is the implementation below, we just swap the val of the two node, if required to swap the two node:
swap two nodes (node1->next and node2->next) in a linked list,
– first, swap(node1->next, node2->next),
– then, swap(node1->next->next, node2->next->next).

Time Complexity: O(n)
Space Complexity: O(1)

Solution4
Idea: modify beyond the original LinkedList, iterate the list, when the val of the current node is less than x, than move this node to the front of the list

Time Complexity: O(n)
Space Complexity: O(1)

Code:
http://www.jyuan92.com/post-449
回复

使用道具 举报

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

本版积分规则

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