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

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

🔗
bitcpf 2014-6-26 00:52:45 | 只看该作者
全局:
【解题思路】empty/last node could not be deleted. copy the data from the next node to current node, and link current node to next.next node
【时间复杂度】O(1)
【空间复杂度】O(1)
【gist link】https://gist.github.com/bitcpf/943a20fc760f8ca4f6d3

评分

参与人数 1大米 +7 收起 理由
wrj5518 + 7

查看全部评分

回复

使用道具 举报

🔗
heycinderella 2014-6-26 02:45:11 | 只看该作者
全局:
本帖最后由 heycinderella 于 2014-6-26 02:55 编辑

【解题思路】
// Ask the interviewer if this means that the middlenode won't be the first or the last. If it is the first it doesn't matter. However if it is the last it can't be deleted. I assume the node that is to be deleted is not the last.

* Copy the value of each following node back one step, and put null after the 2nd to last node.
【时间复杂度】
O(n)
【空间复杂度】
O(1)
【gist link】
https://gist.github.com/XiaoxiaoLi/f4ebb8143890558ac5ff

做完才发现书里答案那么简单,智商啊。。。其实就是把n下一个node的data copy过来,然后直接删掉n.next即可。。。那样时间空间都是O(1)了吧

评分

参与人数 1大米 +7 收起 理由
wrj5518 + 7

查看全部评分

回复

使用道具 举报

🔗
habina 2014-6-26 07:33:52 | 只看该作者
全局:

【解题思路】
Copy the following pointer content, and relink the next to the next next pointer
【时间复杂度】
O(1)
【空间复杂度】
O(1)
【gist link】
https://gist.github.com/habina/1effe686ec65dbadf1ec

补充内容 (2014-6-28 10:18):
@ivycheung1208 嗯,是的,谢谢提醒,我准备用python重写

点评

最好还是释放一下指针啦,c里面貌似是free()  发表于 2014-6-28 09:58

评分

参与人数 1大米 +7 收起 理由
wrj5518 + 7

查看全部评分

回复

使用道具 举报

🔗
兰橘清檬 2014-6-27 06:29:14 | 只看该作者
全局:
【解题思路】
只是传入node,那么copy当前需要删除的node的下一个结点的数据到当前结点,然后当前结点连接下一个结点的next
【时间复杂度】
O(1)
【空间复杂度】
O(1)
【gist link】
https://gist.github.com/JoyceeLee/16128f844bfb476eb21c

评分

参与人数 1大米 +7 收起 理由
wrj5518 + 7

查看全部评分

回复

使用道具 举报

🔗
Neal 2014-6-27 10:20:20 | 只看该作者
全局:

【解题思路】Move the value of the next node to current node, remove next node. It's impossible if current node is the last node in the list.
【时间复杂度】O(1)
【空间复杂度】O(1)
【gist link】https://gist.github.com/nealhu/f5dcf011d595afa43278

评分

参与人数 1大米 +7 收起 理由
wrj5518 + 7

查看全部评分

回复

使用道具 举报

🔗
jason51122 2014-6-27 14:04:32 | 只看该作者
全局:
【解题思路】Update the current node's value to the next node's value. Skip the next node.
【时间复杂度】O(1)
【空间复杂度】O(1)
【gist link】https://gist.github.com/jason51122/94802d43cf85c27ccd29

评分

参与人数 1大米 +7 收起 理由
wrj5518 + 7

查看全部评分

回复

使用道具 举报

🔗
pud 2014-6-28 01:42:00 | 只看该作者
全局:
【解题思路】
  把next node的data给当前的node,再删除next node
【时间复杂度】
   O(1)
【空间复杂度】
   O(1)
【gist link】https://gist.github.com/yokiy/b5bbba6b2bdb36327a29

评分

参与人数 1大米 +7 收起 理由
wrj5518 + 7

查看全部评分

回复

使用道具 举报

🔗
jyh橘子 2014-6-28 02:59:24 | 只看该作者
全局:
【解题思路】 copy  the data from the next node over to the current node, remove the next node
【时间复杂度】O(1)
【空间复杂度】O(1)
【gist link】https://gist.github.com/jyhjuzi/3cf87cd4799352c6e4d9

评分

参与人数 1大米 +7 收起 理由
wrj5518 + 7

查看全部评分

回复

使用道具 举报

🔗
ivycheung1208 2014-6-28 09:55:24 | 只看该作者
全局:
【解题思路】
***from solution***
copy data from the next node over, then delete the next node
(assume data type is integer)
【时间复杂度】
O(1)
【空间复杂度】
O(1)
【gist link】
https://gist.github.com/637c9366423ebd2ad8f0
【test case】
n = 0, list = {1, 2, 3, 4} invalid index
n = 1, list = {1, 2, 3, 4} delete the first element
n = 4, list = {1, 2, 3, 4} cannot delete the last element
回复

使用道具 举报

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

本版积分规则

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