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

[CareerCup] 【第三轮】6.16-6.22 CareerCup 1.3

🔗
guchang 2014-6-18 16:16:59 | 只看该作者
全局:
【解题思路】统计两个字符串的字符出现次数,统计结果相同则permutation is true.
【时间复杂度】O(N)
【空间复杂度】O(1)
【gist link】https://gist.github.com/guchang/9ba132f3a99399078a74
回复

使用道具 举报

🔗
bitcpf 2014-6-18 22:52:28 | 只看该作者
全局:
【解题思路】If the length of the strings are different, retrun false. Assume all char in the strings are ASCII, use 2 int arrays to store the number of chars in each string, then do a subtraction of the arrays, if all of the elements are 0, it is true.
Actually could be solved by Hash...
【时间复杂度】O(N)
【空间复杂度】O(1)
【gist link】https://gist.github.com/bitcpf/bc83a56c7c3ef44187cb
回复

使用道具 举报

🔗
zZ-IT 2014-6-19 03:07:11 | 只看该作者
全局:
【解题思路】Assuming all the characters are from ASCii. First, we should judge if the lengths of two string are the same. Then we can use an array to store the times of appearing of one character in the first string. Then we subtract the number of responding position of the array recording to the second string if it has the same character.
【时间复杂度】O(N)
【空间复杂度】O(1)
【gist link】https://gist.github.com/ZhuGuanyu/9f9f2d1bb3e38cfcc373
回复

使用道具 举报

🔗
tonygxxx1212 2014-6-19 05:18:37 | 只看该作者
全局:
【解题思路】use an counter[256] (for extended ASCII), iterate str1 and str2, convert char into int as index of counter: for str1, ++counter[index]; for str2, --counter[index]. return false if found counter[i] is not equal to 0, else return true
【时间复杂度】O(N)
【空间复杂度】O(1)
【gist link】https://gist.github.com/xun-gong/6f344017108913a9ec8c
回复

使用道具 举报

🔗
pud 2014-6-19 05:23:27 | 只看该作者
全局:
【解题思路】字符串先转换成列表,比较长度。 长度一样,再把每个字符转换成ASCII码
【时间复杂度】O(N)
【空间复杂度】O(1)
【gist link】https://gist.github.com/yokiy/23cfde3e7d270be30e2b
回复

使用道具 举报

🔗
Neal 2014-6-19 07:48:17 | 只看该作者
全局:
【解题思路】Use a array of length 256 to record the count of each char in the string
【时间复杂度】O(N)
【空间复杂度】O(1)
https://gist.github.com/nealhu/07e151dcbf188516af42
回复

使用道具 举报

🔗
heycinderella 2014-6-19 09:13:16 | 只看该作者
全局:
【解题思路】
/**
         * Assume the string falls under a certain encoding. Use an extra constant
         * size array of integers to store the frequency of each character in str1,
         * for each character in str2, minus the frequency array's value by 1. In
         * the end, check if each element in the frequency array is 0, if not then
         * str1 is not a permutation of str2.
【时间复杂度】
O(n)
【空间复杂度】
O(1)
【gist link】
https://gist.github.com/XiaoxiaoLi/4846b24cf7adfb5d4053

点评

cool! one tiny thing is you don't need to define local variable c1/c2 in the for loop, just use freqs[str1.charAt(i)]++ straight forward:)  发表于 2014-6-19 13:15
回复

使用道具 举报

🔗
3angFeng945 2014-6-19 10:13:02 | 只看该作者
全局:
【解题思路】刚开始想到的还是 O(n^2)的,然后看了一下,貌似用周一的hash table的解法,O(n)就可以实现
【时间复杂度】O(n)
【空间复杂度】O(1)
【gist link】https://gist.github.com/sddxhwj/99314e73d8d2c4d289bb

回复

使用道具 举报

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

本版积分规则

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