📣 VIP通行证夏日特惠 限时立减$68
12
返回列表 发新帖
楼主: pure0909
跳转到指定楼层
上一主题 下一主题
收起左侧

[CareerCup] 【第四轮】4.6 - 4.12 Career Cup 2.2

🔗
daphne_ying 2015-4-13 21:39:35 | 只看该作者
全局:
【solution】
use two pointers, firstly move fast runner k-1 steps forward, and then move two pointers both one step everytime until the fast runner hit the end, return the slow runner
【time】
O(n)
【space】
O(1)
【gist link 】
https://gist.github.com/kelly-us/69c2c202a0a85ae378b2
回复

使用道具 举报

🔗
iker01 2015-4-14 09:47:50 | 只看该作者
全局:
【解题思路】
# use two pointers, one move first for k - 1 step
# then move first and second pointer at the same time
# return the second value until the first node reaches the final spot
【时间复杂度】
O(n)
【空间复杂度】
O(1)
【gist link】
https://gist.github.com/zhangjiang2013/17431cb8a347cc104562
回复

使用道具 举报

🔗
A30041839 2015-4-14 14:38:51 | 只看该作者
全局:
[solution]
use two pointers, make the fast pointer go k steps than the slow pointer
[time]
O(n)
[space]
O(1)
[gist]
https://gist.github.com/A30041839/0862e9279c7c14874e22
回复

使用道具 举报

🔗
sevenwonder 2015-4-19 01:24:52 | 只看该作者
全局:
[solution]
1. slow and faster ptr. 2. recursion
[time]
1. O(n), 2. O(n)
[space]
1. O(1), 2.O(n)
[gist]
https://gist.github.com/songpu2015617/8ac85fd5ecb6b3cc3119/edit()
回复

使用道具 举报

🔗
Godbless 2015-5-27 09:37:18 | 只看该作者
全局:
【解题思路】Iterative methods - use two pointers, one is kth ahead of the other one. Then forward these
        two pointers with the same pace. When the first pointer reach the end, the second pointer
        will point to the kth element to the last element
【时间复杂度】O(n)
【空间复杂度】O(1)
【gist link] https://github.com/StephenWeiXu/ ... aster/Chap2/2_2.cpp
【test case】(optional,如果觉得比较好,欢迎贴出来分享)
回复

使用道具 举报

🔗
voiding 2015-5-31 02:28:48 | 只看该作者
全局:
【解题思路】
use two pointers. Move runner pointer K steps. and then move walker and runner pointer simultaneously. When the runner hit the end of the linked list, return walker.
【时间复杂度】
O(n)
【空间复杂度】
O(1)

GistLink including test cases
https://gist.github.com/mogutou1214/8c3d5871ea1a7da4d234
回复

使用道具 举报

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

本版积分规则

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