📣 黑五价提前开抢|VIP一年通行证5折,蓝莓、Offer多多同步特惠
楼主: pure0909
跳转到指定楼层
上一主题 下一主题
收起左侧

[CareerCup] 【第四轮】3.30 -4.5 Career Cup 1.3

全局:
【解题思路】
* The idea is quite similar to the first question
* We use the ASCII code to count how many times each character appears in the first string
* Then We reduce one in the count for each character appears in the second string
* if we get any count element less than 0, it means difference

【时间复杂度】
O(n)
【空间复杂度】
O(1)
【gist link]
https://gist.github.com/leonw007/4f5702fc74766522daa8
【test case】included in the above link

评分

参与人数 1大米 +7 收起 理由
pure0909 + 7 感谢分享!

查看全部评分

回复

使用道具 举报

🔗
芒果舞 2015-4-6 10:00:40 | 只看该作者
全局:
本帖最后由 芒果舞 于 2015-4-6 10:02 编辑

【解题思路】
不考虑空白,区分大小写,创建一个256的数组来储存第一个字符串里的字符, 再对第二个字符串遍历看是否一样。
【时间复杂度】
O(n)
【空间复杂度】
O(1)
【gist link]
https://gist.github.com/LinyinWu/deddefd0cb379783e61b
【test case】
"abc";
"bca";
"acd";
"cab";

评分

参与人数 1大米 +7 收起 理由
pure0909 + 7 感谢分享!

查看全部评分

回复

使用道具 举报

🔗
sevenwonder 2015-4-6 10:10:27 | 只看该作者
全局:

【解题思路】
1. 先排序,然后逐一比较是否相等。
2. 见一个大小是256整数数组,遍历第一个字符串时,将相应字符出现的次数加1;遍历第二个字符串时, 将相应字符出现的次数减1。最后如果数组中256个数都为0,说明两个字符串是一对变位词。

【时间复杂度】
1. O(nlogn) 2 O(n)
【空间复杂度】
O(1)
【gist link]
https://gist.github.com/songpu2015617/494d45199a1356787020

评分

参与人数 1大米 +7 收起 理由
pure0909 + 7 感谢分享!

查看全部评分

回复

使用道具 举报

🔗
Howie 2015-4-6 11:20:35 | 只看该作者
全局:
【解题思路】
Sort the two strings.
【时间复杂度】
O(nlogn)
【空间复杂度】
O(N)
When we sort strings, we create a new string in java.
【gist link]
https://gist.github.com/Howiezhang226/c35feee252876c5c1ed3

评分

参与人数 1大米 +7 收起 理由
pure0909 + 7 感谢分享!

查看全部评分

回复

使用道具 举报

🔗
干.什么 2015-4-12 03:49:01 | 只看该作者
全局:
JamesJi 发表于 2015-3-30 21:00
【解题思路】
可以先将两个string排序,然后按位比较
【时间复杂度】

https://gist.github.com/JamesJi9277/65f609a02218ff9cdd61#file-1-3-java-L13


时间复杂度应该是 O(N), where N means the length of given strings. sort 函数会生成两个新的 String。
回复

使用道具 举报

🔗
干.什么 2015-4-12 03:54:12 | 只看该作者
全局:
iker01 发表于 2015-4-1 12:00
解题思路】
using the sort method first, then compare the two sorted string
【时间复杂度】

Quite neat solution!

Python's built-in function - sorted() will return a new list and leave the original string unchanged. So, basically I think the space complexity should be O(N).
回复

使用道具 举报

🔗
干.什么 2015-4-12 04:29:14 | 只看该作者
全局:
来晚啦!

【解题思路】
  Permutation means same characters with different order, so we can sort two strings in ascending order then compare whether they equal to each other.
【时间复杂度】
O(nlogn)
【空间复杂度】
O(n)
【gist link]
Java solution
【test case】
isPermutation(null, null)
回复

使用道具 举报

🔗
JamesJi 2015-4-12 08:32:00 | 只看该作者
全局:
slaink 发表于 2015-4-2 15:35
所谓用堆是指存一个augmented 堆吗?每个element包含字符以及他的出现次数,然后靠次数构造堆?

仔细 ...

请问一下什么叫做用硬盘做hash以及什么是augment heap,感觉自己heap方面的知识非常的薄弱
回复

使用道具 举报

🔗
JamesJi 2015-4-12 08:39:46 | 只看该作者
全局:
stellari 发表于 2015-4-2 21:10
我看你的回复,你否把我说的“字符串列表”(a list of strings)理解成了“字符列表”(a list of char ...

发现看您的评论也会有很大的收获!感觉需要恶补基本功了
回复

使用道具 举报

🔗
JamesJi 2015-4-12 08:42:28 | 只看该作者
全局:
stellari 发表于 2015-4-2 21:10
我看你的回复,你否把我说的“字符串列表”(a list of strings)理解成了“字符列表”(a list of char ...

这个思想算是mapreduce吧?
回复

使用道具 举报

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

本版积分规则

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