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

[CareerCup] 【第三轮】6.30-7.6 CareerCup 2.7

🔗
Neal 2014-7-1 07:48:04 | 只看该作者
全局:
grassgigi 发表于 2014-6-29 22:55
【解题思路】
Recursion

Recursion占用栈空间,java里面应该还是O(n)空间

点评

good point. thx!  发表于 2014-7-1 12:44
回复

使用道具 举报

🔗
jyh橘子 2014-7-2 06:59:09 | 只看该作者
全局:
【解题思路】
1. if we are allowed to modify the linkedlist, we can reverse the second half in place  and then compare the first half with the second half
2. push elements in the first half to a stack and then compare them with the second half
【时间复杂度】1. O(N)   2. O(N)
【空间复杂度】1. O(1)   2. O (N)
【gist link】 https://gist.github.com/jyhjuzi/32617c7992f3807bd098
回复

使用道具 举报

🔗
wilbert 2014-7-2 12:13:47 | 只看该作者
全局:
【解题思路】
first pass to push every elements in the stack, second pass to compare the pop element from the stack with the list.
【时间复杂度】
O(N)
【空间复杂度】
O(N)
【gist link】
https://gist.github.com/iwilbert/cdb703fcb9b665551ae6
回复

使用道具 举报

🔗
jing0328 2014-7-2 21:36:30 | 只看该作者
全局:
【解题思路】store elements into a stack and pop element from stack and compare to the list
【时间复杂度】O(n)
【空间复杂度】O(n)
【gist link】https://gist.github.com/startupjing/1f3b016aa1cc20187ec8
回复

使用道具 举报

🔗
兰橘清檬 2014-7-3 01:18:05 | 只看该作者
全局:
【解题思路】
reverse the list and compare with the original one
【时间复杂度】
O(n)
【空间复杂度】
O(n)
【gist link】
https://gist.github.com/JoyceeLee/9bc2f720dac8e06c69a1
回复

使用道具 举报

🔗
兰橘清檬 2014-7-3 01:19:13 | 只看该作者
全局:
【解题思路】
use a stack to reverse the first half of the list and then compare
【时间复杂度】
O(n)
【空间复杂度】
O(n)
【gist link】
https://gist.github.com/JoyceeLee/23e37c323192dd6f3405
回复

使用道具 举报

🔗
jason51122 2014-7-3 12:28:05 | 只看该作者
全局:
【解题思路】Use slow and fast pointers to find the middle of the linked list. Use a stack to keep track of all integers to see if it is a palindrome.
【时间复杂度】O(N)
【空间复杂度】O(N)
【gist link】https://gist.github.com/jason51122/ca90d321da5a21c80ed1
回复

使用道具 举报

🔗
锦木千束 2014-7-4 00:23:04 | 只看该作者
全局:
【解题思路】use two iterators to find the middle node and put the first half of the list into a new stack
then compare the second half of list with the stack
【时间复杂度】O(n)
【空间复杂度】O(n)
【gist link】https://gist.github.com/weazord/2936434fce6597344593
回复

使用道具 举报

🔗
habina 2014-7-4 13:04:50 | 只看该作者
全局:
============================================================================
Question        : 2.7  Implement a function to check if a linked list is a palindrome.
Solution        : Save all elements in to a python list, and use slicing to check if
                    it is a palindrome
Time Complexity : O(N)
Space Complexity: O(N)
Gist Link       : https://gist.github.com/habina/20fd04778919563f0126
============================================================================
回复

使用道具 举报

🔗
monsoonle 2014-7-5 02:00:54 | 只看该作者
全局:
【解题思路】slow-fast pointers find mid node, break it, reverse half and count it, startover form heads of both list, compare value
【时间复杂度】O(n)
【空间复杂度】O(1)
【gist link】稍后编辑
回复

使用道具 举报

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

本版积分规则

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