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

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

🔗
habina 2014-6-28 17:12:44 | 只看该作者
全局:
"""
============================================================================
Solution        : Faster pointer moves two steps at a time,
                    slower pointer moves onw step at a time,
                    after their first time meet,
                    reset fater pointer back to head
                    return slower when they meet again
Time Complexity : O(n)
Space Complexity: O(1)
Gist Link       : https://gist.github.com/habina/d8bbd5fbe1567502c676
============================================================================
"""
回复

使用道具 举报

🔗
bitcpf 2014-6-29 05:09:24 | 只看该作者
全局:

【解题思路】  No idea till read the book... faster pointer and slower pointer, slower pointer move 1 step each time, faster pointer move 2 steps each time. When they meet, assign one of them as the header of the linked list, when they meet again, output the node
【时间复杂度】O(N)
【空间复杂度】O(1)
【gist link】 https://gist.github.com/bitcpf/7790d1e5f963ae582fe2
回复

使用道具 举报

🔗
pud 2014-6-29 08:02:08 | 只看该作者
全局:
【解题思路】 看书上的解法,用快慢指针
【时间复杂度】
O(N)
【空间复杂度】
O(1)
【gist link】 https://gist.github.com/yokiy/da71157d9de7dc6491ba
回复

使用道具 举报

🔗
heycinderella 2014-6-29 09:51:47 | 只看该作者
全局:

【解题思路】 用HashSet存每个node,遇到一样的就返回。再就是书上space O(1)的解法了
【时间复杂度】
O(N)
【空间复杂度】
O(n)
【gist link】 https://gist.github.com/XiaoxiaoLi/2dcd9f629fef8469a1f7
回复

使用道具 举报

🔗
jing0328 2014-6-29 17:06:35 | 只看该作者
全局:
【解题思路】assume one loop in the list, use a hashset to store node, traverse the list and see if a node has already been in the set
【时间复杂度】O(n)
【空间复杂度】O(n)
【gist link】https://gist.github.com/startupjing/33c7e74aca2ab63441ae
回复

使用道具 举报

🔗
Neal 2014-6-30 11:08:23 | 只看该作者
全局:
【解题思路】Use fast and slow runner. If fast and slow runner meet, there is a loop.
【时间复杂度】O(n)
【空间复杂度】O(1)
【gist link】https://gist.github.com/nealhu/e333fc1162464261f663
回复

使用道具 举报

🔗
ivycheung1208 2014-6-30 11:57:43 | 只看该作者
全局:
本帖最后由 ivycheung1208 于 2014-6-29 23:00 编辑

【解题思路】
1. Floyd's algorithm
2. Brent's algorithm
C.f. wiki page: cycle detection
【时间复杂度】
O(λ + μ)
【空间复杂度】
O(1)
【gist link】
https://gist.github.com/04fef6f51373925ab3a6
【test case】
null list
no loop
common case
回复

使用道具 举报

🔗
锦木千束 2014-7-1 10:50:44 | 只看该作者
全局:
【解题思路】Fast/Slow 指针
【时间复杂度】O(n)
【空间复杂度】O(1)
【gist link】https://gist.github.com/weazord/8ddffcbd65ed86fb00aa
回复

使用道具 举报

🔗
jason51122 2014-7-2 14:00:05 | 只看该作者
全局:
【解题思路】Use slow and fast pointers. When they meet, move slow pointer to head. Then move two pointers with the same pace until they meet.
【时间复杂度】O(N)
【空间复杂度】O(1)
【gist link】https://gist.github.com/jason51122/cafb1093ab8fb82ee0b0
回复

使用道具 举报

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

本版积分规则

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