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

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

🔗
林微熙 2014-6-24 06:34:36 | 只看该作者
全局:
【解题思路】
不用hash set:两个指针,第一个current就正常遍历链表;第二个runner每一次都遍历current之前的,并查找重复的。如果有,则current所指向的。
需要注意的是,删除current的时候并不能直接删除,因为需要让current之前的那一个的next指向current之后的那一个。所以我们让current永远指向当前node的前一个即可。
基本上一样
【时间复杂度】
不用hash set: O(n^2)
【空间复杂度】
不用hash set: O(1)
【gist link】
https://gist.github.com/hilda8519/9d542359b602a1bb647c
回复

使用道具 举报

🔗
heycinderella 2014-6-24 09:26:22 | 只看该作者
全局:
【解题思路】
HashSet来存unique value,碰见一样的就删除
【时间复杂度】
O(n)  
【空间复杂度】
O(n)  

【解题思路】
不用extra buffer,用两个pointer,一个p1从前往后扫,另一个p2从p2下一个扫到结尾,如果碰见一样的就删除,如果到头就回p1下一个再重新往后扫,直到p1到达倒数第一个点。注意判断p1不能是null
【时间复杂度】
O(n^2)  
【空间复杂度】
O(1)  
【gist link】
https://gist.github.com/XiaoxiaoLi/8559f31eace496fc6fec
回复

使用道具 举报

🔗
wilbert 2014-6-24 10:42:47 | 只看该作者
全局:
【解题思路】
use hashtable to record the elements seem, if an element has seem before, remove it from the list
FOLLOW UP:
(1) If the order of the elements does not matter, sort the linked list first, then remove the duplicate elements
(2) If the order should be the same as original, brute-force solution
【时间复杂度】
O(N)
FOLLOW UP:
(1) O(N Log N)
(2) O(N^2)
【空间复杂度】
O(N)
FOLLOW UP:
(1) O(1)
(2) O(1)
【gist link】
https://gist.github.com/iwilbert/155842366920552262d7
回复

使用道具 举报

🔗
bitcpf 2014-6-24 10:52:43 | 只看该作者
全局:
【解题思路】Use hash table to determine if there is any duplicate item, if not, copy the item to a new list
Follow up: compare each member in the list, then delete the duplicated item
【时间复杂度】
1. O(n)   2. O(n^2)
【空间复杂度】
1. O(n)  2. O(1)
【gist link】
https://gist.github.com/bitcpf/7ce6a0976d775bd00724
回复

使用道具 举报

🔗
锦木千束 2014-6-24 20:27:19 | 只看该作者
全局:
【解题思路】用hashcode判断重复。 follow up: 没啥思路,挨个比较
【时间复杂度】O(n) follow up:O(n^2)
【空间复杂度】O(n) follow up:O(1)
【gist link】https://gist.github.com/weazord/179e61fee75273b29f8a
回复

使用道具 举报

🔗
guchang 2014-6-24 21:24:07 | 只看该作者
全局:
【解题思路】用hashcode判断重复, 有重复,删除结点。
【时间复杂度】O(n)
【空间复杂度】0~O(n)
【gist link】https://gist.github.com/guchang/c4b4c2ee2b7656b55d70
回复

使用道具 举报

🔗
heycinderella 2014-6-25 00:43:25 | 只看该作者
全局:
wilbert 发表于 2014-6-24 10:42
【解题思路】
use hashtable to record the elements seem, if an element has seem before, remove it fr ...

赞提出是否order matter
回复

使用道具 举报

🔗
Neal 2014-6-25 10:18:49 | 只看该作者
全局:
【解题思路】for each node, examine all its previous nodes and check if it's a duplicate.
【时间复杂度】O(n^2)
【空间复杂度】O(1)
【gist link】https://gist.github.com/nealhu/7047592e469cd42fdf1f
回复

使用道具 举报

🔗
RealityPC 2014-6-25 10:23:14 | 只看该作者
全局:
Method1
【解题思路】
Use hashtable to determine if a element is duplicate. If it is, delete it from the list.
【时间复杂度】O(N)
【空间复杂度】O(N)

Method2
【解题思路】
Two iterator compare element in list. Make sure elements before iterator i is unique. Any element after i that duplicated will be removed.
【时间复杂度】O(N^2)
【空间复杂度】O(1)

【gist link】https://gist.github.com/pchong90/ca41bc80780c2d1329ce
回复

使用道具 举报

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

本版积分规则

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