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

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

🔗
cqx83 2013-2-18 04:20:22 | 只看该作者
全局:
mazl123321 发表于 2013-2-17 10:19
1. both str must have same length
2. for same char, both str have same count

感觉用HashMap的话就麻烦了,虽然也是O(n)
回复

使用道具 举报

🔗
mazl123321 2013-2-18 09:47:09 | 只看该作者
全局:
cqx83 发表于 2013-2-18 04:20
感觉用HashMap的话就麻烦了,虽然也是O(n)

Yes, you are right, thanks a lot
回复

使用道具 举报

🔗
ac/dc 2013-2-18 14:04:02 | 只看该作者
全局:
1. check if there is a duplicate in the visited zone. If yes, do nothing, ++p2. If no, copy *p2 to *tail and increment tail++. (tail is "not included")
Time: n^2 Space: 0

2. hashtable, easy. Time: n Space: 256

https://gist.github.com/JasonGitHub/4975307
回复

使用道具 举报

🔗
jerrysun 2013-2-19 00:42:27 | 只看该作者
全局:
https://github.com/JerrySun363/C ... k1/Permutation.java

1. 比较长度
2.用bitmap(开数组记录每个char出现的字数,string 1 用++, string 2 --),然后check 是不是都是 0;
--------------
其实对permutation的定义不是很明白,我按照每个character 出现的次数一样来做的。
还有一个问题是Java的char取值范围是0-65535,但是我只取了0-255,如果出现中文或者别的文字的话就跪了。我想请教一下如果这个题目里的string不局限于 ASCII时应该怎么考虑?开一个65535的数组还是先排序再比较?

点评

如果不局限于ASCII的话我大概会用HashMap.......  发表于 2013-2-20 05:20
这本书里string的char默认是0-255的,参见第一题的标答。  发表于 2013-2-19 09:50
回复

使用道具 举报

全局:
jerrysun 发表于 2013-2-19 00:42
https://github.com/JerrySun363/CareerCup/blob/master/Week1/Permutation.java

1. 比较长度

I see most of you guys solve it this way. Before you solve the problem during the interview, you can always ask questions, even ask for examples.
http://n1b-algo.blogspot.com/2009/01/string-permutations.html
This link may help you understand what is permutation.
The code seems good for me. :)
回复

使用道具 举报

全局:
本帖最后由 luglyduckling90 于 2013-2-19 05:56 编辑

I check both length first, if the length equals: convert to charArray and sort. Then convert back to string and compare.
Don't know what's the complexity.. But I know it would be very large... Need some advices.

https://gist.github.com/lynntian/4981111
回复

使用道具 举报

🔗
starcroce 2013-2-19 07:57:59 | 只看该作者
全局:
python无脑强A流,先比较长度,如果一样就sort再比较。。。我觉得用hash的话可以做到O(n),但我不知道python是怎么比较两个list的,求教达人
https://gist.github.com/starcroce/4981843
回复

使用道具 举报

🔗
Kimurate 2013-2-19 09:45:44 | 只看该作者
全局:
本帖最后由 Kimurate 于 2013-2-19 09:59 编辑

overview:
method1: Test every char in str1, if it is in the str2,  then record its index in str2 using an int array. Whenever a char can't be found, return false.method2: Use a int array[256], plus 1 to the array[char in str1], minus 1 to the array[char in str2], if the result array is not all 0, return false.

C language:https://gist.github.com/hukun01/4982375
回复

使用道具 举报

🔗
Kimurate 2013-2-19 09:48:23 | 只看该作者
全局:
starcroce 发表于 2013-2-19 07:57
python无脑强A流,先比较长度,如果一样就sort再比较。。。我觉得用hash的话可以做到O(n),但我不知道pytho ...

这这……我只能说 脚本语言就是不一样啊。
这个比较是内建的,查文档应该能知道,估计已经是最优化了。
回复

使用道具 举报

全局:
https://gist.github.com/Toanso/4984905
回复

使用道具 举报

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

本版积分规则

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