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

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

🔗
jerrysun 2013-2-19 00:37:27 | 只看该作者
全局:
sunnyroom 发表于 2013-2-18 22:21
用了最笨的办法,每个字符循环比较。时间,空间复杂度什么的,还不知道怎么算,明天学习一下,然后看一下大 ...

可以先排序,再比较吧。
不排序的话,时间复杂度O(N^N),排序的话,排序是O(n lgn),比较是O(N)
回复

使用道具 举报

🔗
lazyGoose 2013-2-19 00:43:01 | 只看该作者
全局:
Compare the 1st char in a string with 2nd to the last; then compare the 2nd with 3rd to the last................ If two char are the same, then return FALSE.

https://gist.github.com/lazyGoose/4978681
回复

使用道具 举报

🔗
lazyGoose 2013-2-19 00:51:31 | 只看该作者
全局:
jerrysun 发表于 2013-2-18 19:34
https://gist.github.com/JerrySun363/0c7fb3b4d9c54aa41171

其实不是很清楚能用什么样的API

学习了...
HashSet does not allow duplicates.
回复

使用道具 举报

🔗
SunnyDay1022 2013-2-19 02:59:21 | 只看该作者
全局:
本帖最后由 SunnyDay1022 于 2013-2-19 05:52 编辑

https://github.com/swang1022/car ... 1.1/hasUniqChar.cpp
idea: sort the string first then compare adjacent character

bitmap的方法还不是太懂,学习中~
回复

使用道具 举报

🔗
willians512 2013-2-19 06:20:50 | 只看该作者
全局:
https://gist.github.com/bigteeth/4981284

Using the Bitmap is a better way to implement it. The running time is O(N).

回复

使用道具 举报

🔗
sunnyroom 2013-2-19 15:25:51 | 只看该作者
全局:
jerrysun 发表于 2013-2-18 19:34
https://gist.github.com/JerrySun363/0c7fb3b4d9c54aa41171

其实不是很清楚能用什么样的API

第一个HashSet的时间复杂度是O(n)?  hashset.add 不要考虑?
回复

使用道具 举报

🔗
sunnyroom 2013-2-19 15:31:35 | 只看该作者
全局:
lazyGoose 发表于 2013-2-19 00:43
Compare the 1st char in a string with 2nd to the last; then compare the 2nd with 3rd to the last.... ...

大多数人都是这么写的。
我还忘了string.length()-1
回复

使用道具 举报

🔗
superdry 2013-2-19 16:28:09 | 只看该作者
全局:
https://github.com/knightelvis/a ... niqueCharacter.java
Two implementations. One is using bitmap and the other one is using sorting and comparing.
回复

使用道具 举报

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

使用道具 举报

🔗
jerrysun 2013-2-19 20:48:20 | 只看该作者
全局:
sunnyroom 发表于 2013-2-19 15:25
第一个HashSet的时间复杂度是O(n)?  hashset.add 不要考虑?

HashSet Add操作是O(1)的,N个元素是O(N)的
回复

使用道具 举报

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

本版积分规则

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