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

[CareerCup] [第二轮] 2/18-2/24 CareerCup 1.1

🔗
davidcool 2013-5-10 12:51:19 | 只看该作者
全局:
本帖最后由 davidcool 于 2013-5-10 13:01 编辑

总结:
1.1 mplement an algorithm to determine if a string has all unique characters. What if you cannot use additional data structures?
边界条件:
1.长度为0(null)直接返回false,因为啥也没有啊
多种思路:
1.可以先排序再判断,不过需要原地排序
Clarification:
1.要问清是否可以改变原字符串,可以的话才能排序呢
总结:
if 如果可以用额外空间
    if 是unicode, 用hashtable
    if 是ascii, bitmap 就解决了
else
    if 不可以更改现有代码, 先原地快排再邻居比较
    else 就两层loop解决吧
回复

使用道具 举报

🔗
davidcool 2013-5-13 09:05:24 | 只看该作者
全局:
回复

使用道具 举报

🔗
davidcool 2013-5-13 09:09:37 | 只看该作者
全局:
不知道面试的时候会不会要求把递归的快排变成迭代?
有木有大神指导一下这个是不是重点?
回复

使用道具 举报

🔗
voiding 2013-5-15 12:53:18 | 只看该作者
全局:
https://gist.github.com/mogutou1214/5581704
刚刚开始练习写CODE,用最土的O(n*n)
回复

使用道具 举报

🔗
MrKeke 2013-6-18 18:54:39 | 只看该作者
全局:
I am using brute force to do this problem

https://gist.github.com/yaoqimin2013/5804402
回复

使用道具 举报

🔗
stpddream 2013-10-28 01:40:36 | 只看该作者
全局:
另外sort法也可以用inplace的merge sort。。merge上来如果相同就删掉一个,这般sort好就不必再过一遍了
回复

使用道具 举报

🔗
tracyrongyi 2013-11-2 01:18:52 | 只看该作者
全局:
grassgigi 发表于 2013-2-17 17:43
if we can use additional array, then use bitmap for all characters
with no additional data structur ...

Looks good. BTW, I m wondering is there an easy way to envalue the Bitmap initial value to be all 0, except for the iteration.
回复

使用道具 举报

🔗
冰点 2013-12-23 03:52:12 | 只看该作者
全局:
Fanyare 发表于 2013-2-18 07:10
https://github.com/quantumrose/CareerCup/blob/master/1.1.IsUniqueChars.java

boolean array / bit v ...

Hi Fanyare,
I just read ur code. On method 2, why do u need to %8 to val ?
Thx
回复

使用道具 举报

🔗
冰点 2013-12-23 04:43:17 | 只看该作者
全局:
Fanyare 发表于 2013-2-18 07:10
https://github.com/quantumrose/CareerCup/blob/master/1.1.IsUniqueChars.java

boolean array / bit v ...

Let's see: if val=160, we check "(bitVector[val / 8] & 1 << val % 8) != 0". In this statement, val%8 is always 0 when val is multiple of 16. So if val = 160 again, it won't return false.
回复

使用道具 举报

🔗
GTea 2013-12-23 12:18:06 | 只看该作者
全局:
Use a int, which is 4 bytes, and 32 bits, as a bitmap
https://gist.github.com/GTCoder/8091561
回复

使用道具 举报

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

本版积分规则

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