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

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

🔗
jimwallet 2013-2-17 20:28:37 | 只看该作者
全局:
use additional array to be ascii. space O(n) time O(n)

https://gist.github.com/njcongtou/4971300
回复

使用道具 举报

🔗
moophis 2013-2-17 21:38:29 | 只看该作者
全局:
Use two arrays to map each of two strings, other part is the same as others above.
https://github.com/moophis/careercup/blob/master/1.3.cpp
回复

使用道具 举报

🔗
moophis 2013-2-17 21:41:58 | 只看该作者
全局:
jimwallet 发表于 2013-2-17 20:28
use additional array to be ascii. space O(n) time O(n)

https://gist.github.com/njcongtou/4971300

What if a string with some characters in it occurred more than once?
回复

使用道具 举报

🔗
zuohr 2013-2-17 23:39:38 | 只看该作者
全局:
jimwallet 发表于 2013-2-17 20:28
use additional array to be ascii. space O(n) time O(n)

https://gist.github.com/njcongtou/4971300

Correct me if I am wrong, I think it won't work since you have not taken number of occurance into account, your method would return true if you pass "abb" and "aab" into the method.
回复

使用道具 举报

🔗
zuohr 2013-2-17 23:46:26 | 只看该作者
全局:
本帖最后由 zuohr 于 2013-2-18 00:02 编辑
Arthur2012 发表于 2013-2-17 17:21
Because the ASCII is between 0 to 127, the number of characteristics in each string can be counted. ...


We could make some improvement by adding something like this at the very begining of the function, since there is no fun in comparing two strings with different length:
if(str1.size() == str2.size())
{
// your implementation
}
return false;
回复

使用道具 举报

🔗
Arthur2012 2013-2-17 23:50:18 | 只看该作者
全局:
zuohr 发表于 2013-2-17 23:46
We could make some improvement by add something like this at the very begining of the function, si ...

You are right. I will update my program right now. Thank you!
回复

使用道具 举报

🔗
jimwallet 2013-2-18 00:17:53 | 只看该作者
全局:
本帖最后由 jimwallet 于 2013-2-18 00:20 编辑
zuohr 发表于 2013-2-17 23:39
Correct me if I am wrong, I think it won't work since you have not taken number of occurance into  ...

Thanks. You are right.
To handle that case, the occurance number in ascii array is increased by 1 when we iterate first string. the occurance number in ascii array is decreased by 1 when we iterate second string. Last, we iterate ascii array to check if all values are 0.

https://gist.github.com/njcongtou/4971300
o(n) space and time
回复

使用道具 举报

🔗
mazl123321 2013-2-18 02:19:20 | 只看该作者
全局:
本帖最后由 mazl123321 于 2013-2-18 02:21 编辑

1. both str must have same length
2. for same char, both str have same count

time complx O(n)

https://gist.github.com/mazl123321/4972623
回复

使用道具 举报

🔗
mazl123321 2013-2-18 02:30:40 | 只看该作者
全局:
jimwallet 发表于 2013-2-17 20:28
use additional array to be ascii. space O(n) time O(n)

https://gist.github.com/njcongtou/4971300

awesome solution!
回复

使用道具 举报

🔗
cqx83 2013-2-18 04:17:41 | 只看该作者
全局:
https://gist.github.com/cqx83/4973207
思路,和1.1基本一样,需要新建array记录每个字符的个数比较是否相同。O(n)
已测试
回复

使用道具 举报

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

本版积分规则

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