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

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

🔗
兰橘清檬 2014-6-27 06:42:40 | 只看该作者
全局:
【解题思路】
set 2 list, one of nodes less than x and another of nodes more or equal to x;
insert into the lists from their head
【时间复杂度】
O(n)
【空间复杂度】
O(1)
【gist link】
https://gist.github.com/JoyceeLee/f0c185fa59129c3f74d4
回复

使用道具 举报

🔗
heycinderella 2014-6-27 09:27:38 | 只看该作者
全局:
【解题思路】
Go through the list, if we see a node whose value is smaller than x,
         * delete it and then insert it to the head of the list
【时间复杂度】
O(n)
【空间复杂度】
O(1) if we are allowed to mutate the original list
【gist link】
https://gist.github.com/XiaoxiaoLi/80318ea564c6ad527c8e
回复

使用道具 举报

🔗
RealityPC 2014-6-27 10:55:56 | 只看该作者
全局:
【解题思路】create two list, scan over the original list and store all less elements in one list and all greater elements in another list. combine the two list
【时间复杂度】O(N)
【空间复杂度】O(N)
【gist link】https://gist.github.com/pchong90/f91f6e2c522f28cacbd4
回复

使用道具 举报

🔗
bitcpf 2014-6-28 01:47:15 | 只看该作者
全局:
【解题思路】Traverse the list, separate the list into two part with the original nodes, then return them with a node array.
【时间复杂度】O(n)
【空间复杂度】O(1) use 3 extra Node to save the middle node, larger head, less header
【gist link】https://gist.github.com/bitcpf/f51b82718f54bddfae74
回复

使用道具 举报

🔗
pud 2014-6-28 03:27:38 | 只看该作者
全局:
【解题思路】create two list for less than x and not less x, traverse the list
【时间复杂度】O(n)
【空间复杂度】O(n)
【gist link】https://gist.github.com/yokiy/e60fc4079f4b7f9d3443
回复

使用道具 举报

🔗
心焰 2014-6-28 04:03:46 | 只看该作者
全局:

【解题思路】
Try to make it done without using external space, then need to keep track of head,tail and current processing node.
1. suppose that do not know the tail, then need to traverse it one time
2. traverse the list , if a node is less than x, move it to the head, otherwise, move it to the tail
【时间复杂度】
O(n)
【空间复杂度】
O(1)
【gist link】

补充内容 (2014-6-30 08:32):
https://github.com/FinalF/CarrerUp/blob/master/moveAroundX.java
回复

使用道具 举报

🔗
jyh橘子 2014-6-28 05:51:06 | 只看该作者
全局:
【解题思路】If we are allowed to modify the original linkedlist, we can traverse the whole list and keep the larger nodes unchanged, move the smaller nodes to the front of the linkedlist.   If not,  create two extra linkedlists for smaller nodes and larger nodes and then combine them.
【时间复杂度】O(n)
【空间复杂度】O(1)
【gist link】https://gist.github.com/jyhjuzi/ecaa9bf88b5858fe1f13
回复

使用道具 举报

🔗
Neal 2014-6-28 07:36:19 | 只看该作者
全局:
【解题思路】Use two linked lists, less and greater, if a node is smaller than val, append it to less, if it's larger than val, append it to greater. Then append greater to less.
【时间复杂度】O(n)
【空间复杂度】O(1)
【gist link】https://gist.github.com/nealhu/c63425af7a01dee9e868
回复

使用道具 举报

🔗
锦木千束 2014-6-28 20:08:37 | 只看该作者
全局:
【解题思路】
Ues two linked list: Less and NotLess.
Then iterate the original list and add the nodes to the corresponding list
Return the Less.addAll(NotLess)
【时间复杂度】O(n)
【空间复杂度】O(n)
【gist link】https://gist.github.com/weazord/ccfc5431a6748e968bd2
回复

使用道具 举报

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

本版积分规则

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