查看: 4207| 回复: 31
跳转到指定楼层
上一主题 下一主题
收起左侧

[CareerCup] [第二轮] 2/25-3/3 CareerCup 2.1

全局:

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
Write code to remove duplicates from an unsorted linked list.
FOLLOW UP
How would you solve this problem if a temporary buffer is not allowed?

发帖规范:
http://www.1point3acres.com/bbs/thread-48094-1-1.html
http://www.1point3acres.com/bbs/thread-32423-1-1.html

评分

参与人数 1大米 +10 收起 理由
Kimurate + 10

查看全部评分


上一篇:[第二轮] 2/25-3/3 CareerCup 1.8
下一篇:[第二轮] 2/25-3/3 CareerCup 2.2
推荐
gaohannk 2014-7-3 06:50:37 | 只看该作者
全局:
我的代码。https://gist.github.com/4fffc35734f2223f4199.git
我看到有很多种实现方法,链表和结点分成两个类,或者结点定义成链表的内部类,还有的是只定义了结点类,哪一种比较好呢?如果将两个类分开,属性又是private,那么想在在类外使用属性就要定义很多个设置或获取属性的方法,这样感觉很麻烦啊!
回复

使用道具 举报

🔗
mazl123321 2013-2-24 12:59:56 | 只看该作者
全局:
1. with temp buffer, by using hashSet (no duplicate elements allowed) o(N)
2. set up 2 pointer check all the elements. O(n^2)

https://gist.github.com/mazl123321/5022668
回复

使用道具 举报

🔗
zuohr 2013-2-24 13:41:59 | 只看该作者
全局:
其他方法同楼上,补充一个递归方法的练练手。
链表中所有元素均不相等时,max run time O(N^2), 所有元素均相等时, min run time O(N)。
用递归方法实现,应该也算用了temporary buffer 吧?
https://gist.github.com/Zuohr/5022756
回复

使用道具 举报

🔗
ThunderXu 2013-2-24 18:04:39 | 只看该作者
全局:
https://gist.github.com/ThunderXu/5023278
With Buffer: use a hash_set to record value that already appeared and delete them when they appear again in the linked list
Without Buffer: use a pointer to traverse the linked list and use another pointer to check all values behind of the current value in the process of iterating, if equal than delete
回复

使用道具 举报

🔗
jimwallet 2013-2-24 22:00:04 | 只看该作者
全局:
https://gist.github.com/njcongtou/4998427

1. O(n) use hashset to check existence.
2. O(n^2)
回复

使用道具 举报

🔗
grassgigi 2013-2-25 00:04:54 | 只看该作者
全局:
本帖最后由 grassgigi 于 2013-2-26 15:34 编辑

1. use set
2. pointer with no buffer
https://gist.github.com/chrislukkk/5036595
回复

使用道具 举报

🔗
 楼主| Fanyare 2013-2-25 09:26:48 | 只看该作者
回复

使用道具 举报

🔗
liuzhe1218 2013-2-25 12:30:09 | 只看该作者
全局:
https://gist.github.com/mettaworld/5027747
Java language
use the function random to generate data in linked list, and then search and delete the nodes with repeated data in a loop.
回复

使用道具 举报

🔗
Kimurate 2013-2-26 11:11:26 | 只看该作者
全局:
回复

使用道具 举报

🔗
Kimurate 2013-2-26 11:24:56 | 只看该作者
全局:
Fanyare 发表于 2013-2-25 09:26
https://github.com/quantumrose/CareerCup/blob/master/2.1.DeleteDups.java

你觉得按题目要求,怎么样才算是不使用 temporary buffer 啊?我觉得临时变量也算 temporary buffer,但是不用不行
回复

使用道具 举报

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

本版积分规则

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