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

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

🔗
bainikolaus 2013-2-18 00:40:23 | 只看该作者
全局:
cqx83 发表于 2013-2-17 16:36
https://gist.github.com/cqx83/4970678

测试了是对的 代码也清晰
回复

使用道具 举报

🔗
starcroce 2013-2-18 02:29:43 | 只看该作者
全局:
我不清楚能不能写python,不过我觉得python比较方便,不用考虑内存分配,变量类型之类的。。。先贴一份吧,要是大家不推荐python的话我再转到c/c++上。。。https://gist.github.com/starcroce/4972658

点评

Python is fine. But, you don't, No need to traverse all chars in the string. When find charA[i] = charA[i+1], return false immediately  发表于 2013-2-18 02:41
回复

使用道具 举报

🔗
paradox 2013-2-18 03:12:27 | 只看该作者
全局:
starcroce 发表于 2013-2-18 02:29
我不清楚能不能写python,不过我觉得python比较方便,不用考虑内存分配,变量类型之类的。。。先贴一份吧, ...

I think you need improve your code style. Your python code looks very messy.
Here is mine, you can take it as reference.

https://github.com/lyyjohn45/CP1 ... ster/ifDuplicate.py
回复

使用道具 举报

🔗
starcroce 2013-2-18 03:29:26 | 只看该作者
全局:
paradox 发表于 2013-2-18 03:12
I think you need improve your code style. Your python code looks very messy.
Here is mine, you ca ...

的确不用完全遍历一遍。。。小程序写多了code style的确是个问题,一直也就写个脚本什么的自己想到哪写到哪,跟写现代诗似的。。。这点以后会注意下。。。
回复

使用道具 举报

全局:
https://gist.github.com/lynntian/4973171

Use boolean array, loop over the string. for every char in the array mark true correspondingly in the boolean array.(assume string is in ASCII code)
When the value at that position is already true, return false. Otherwise, after the for loop return true.
回复

使用道具 举报

🔗
czhoume 2013-2-18 06:03:01 | 只看该作者
全局:
I think no more data structure allowed need to be more specified. I will ask if I am in an interview.

Anyway, here is my solution without extra data structure: https://gist.github.com/czhoume/4973720

use a for loop to test each char and only compare to chars that I have tested, because the substring before the current char is unique, otherwise it has returned already.

but it's still O(n^2) time.
回复

使用道具 举报

🔗
 楼主| Fanyare 2013-2-18 07:10:38 | 只看该作者
全局:
https://github.com/quantumrose/C ... .IsUniqueChars.java

boolean array / bit vector: O(n) time, O(1) space
nested loop: O(n^2) time, O(1) space, no additional data structures
回复

使用道具 举报

🔗
Kimurate 2013-2-18 10:55:27 | 只看该作者
全局:

点评

nice job for quicksort  发表于 2013-2-19 09:20
回复

使用道具 举报

🔗
amoscoder 2013-2-18 10:59:34 | 只看该作者
全局:
本帖最后由 amoscoder 于 2013-2-18 11:02 编辑

思路:
   算法1、循环遍历string。每个字符与它后面的所有字符比较,遇到相等的字符返回false。循环到最后没有遇到的话,返回true。
              算法复杂度O(n^2)
   算法2、先sort排序后再循环遍历字符串,每次与它后面的一个字符比较。遇到相等的字符返回false。循环到最后没有遇到的话,返回true。
              算法复杂度O(nlog(n))

https://gist.github.com/KuangyinWang/4974838




回复

使用道具 举报

🔗
Kimurate 2013-2-18 11:17:12 | 只看该作者
全局:
本帖最后由 Kimurate 于 2013-2-18 11:26 编辑
Fanyare 发表于 2013-2-18 07:10
https://github.com/quantumrose/CareerCup/blob/master/1.1.IsUniqueChars.java

boolean array / bit v ...

nice job.有个疑问:关于 method 2 的 if 条件判断,java 编程需要常用位运算么?


点评

不是特别常用吧... 我除了做CareerCup bit manipulation那章的时候以外很少遇到要用位运算  发表于 2013-2-19 09:26
回复

使用道具 举报

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

本版积分规则

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