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

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

🔗
heycinderella 2014-6-25 04:45:27 | 只看该作者
全局:
【解题思路】Use the runner technique. Use two pointers, move the runner k steps ahead
         * of the current pointer (if the runner reaches null it means k is larger
         * than the length, return null), then move them together one step at a
         * time. When the runner reaches the end the current points to the len-k th
         * element.
【时间复杂度】O(N)
【空间复杂度】O(1)
【gist link】https://gist.github.com/XiaoxiaoLi/d9b916553652fbeb6ef3
回复

使用道具 举报

🔗
jason51122 2014-6-25 13:53:29 | 只看该作者
全局:
To Be Implemented
回复

使用道具 举报

🔗
habina 2014-6-26 07:08:31 | 只看该作者
全局:
【解题思路】
  Two pointer point to head, first pointer move forward k elements, then move both pointer together, until the first one reaches the end, return second pointer.
【时间复杂度】
  O(N)
【空间复杂度】
  O(1)
【gist link】
  https://gist.github.com/habina/f521508cef301ac0d18d
回复

使用道具 举报

🔗
Neal 2014-6-26 09:14:39 | 只看该作者
全局:
【解题思路】Calculate the length of the list first, then get the (len-k-1)th element
【时间复杂度】O(N)
【空间复杂度】O(1)
【gist link】https://gist.github.com/nealhu/ff6cd5a1e217d47be280
回复

使用道具 举报

🔗
jason51122 2014-6-26 13:04:56 | 只看该作者
全局:

【解题思路】Use 2 pointers. Keep the distance between slow and fast pointer to k. Move the windows to the end.
【时间复杂度】O(N)
【空间复杂度】O(1)
【gist link】https://gist.github.com/jason51122/2873201611ad2675b5a3
回复

使用道具 举报

🔗
兰橘清檬 2014-6-26 14:33:08 | 只看该作者
全局:
【解题思路】
2 pointers, the first one move k steps then move the pointers together till the the first one touch the end of the list
和 leetcode 上 Remove Nth Node From End of List 类似
【时间复杂度】
O(N)
【空间复杂度】
O(1)
【gist link】
https://gist.github.com/JoyceeLee/2fa8f900432f8759c79f
回复

使用道具 举报

🔗
pud 2014-6-27 09:46:44 | 只看该作者
全局:
【解题思路】
  p1= head, p2指向第k个node。 一起遍历链表
【时间复杂度】
O(N)
【空间复杂度】
O(1)
【gist link】https://gist.github.com/yokiy/7da78a4396e307ced78d
回复

使用道具 举报

🔗
RealityPC 2014-6-27 09:53:57 | 只看该作者
全局:
【解题思路】2 pointers
【时间复杂度】O(N)
【空间复杂度】O(1)
【gist link】https://gist.github.com/pchong90/1f91c296ccfb81a8b639
回复

使用道具 举报

🔗
jyh橘子 2014-6-28 02:45:23 | 只看该作者
全局:
【解题思路】 use two pointers p1 and p2, which are k nodes apart. Iterate the list and stop when p2 hits the end.  
【时间复杂度】O(N)
【空间复杂度】O(1)
【gist link】https://gist.github.com/jyhjuzi/1c751226bdbb31ea3e78
回复

使用道具 举报

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

本版积分规则

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