12
返回列表 发新帖
楼主: pure0909
跳转到指定楼层
上一主题 下一主题
收起左侧

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

🔗
Godbless 2015-4-5 02:13:29 | 只看该作者
全局:
【解题思路】First thing is to see whether the compressed string will be larger than the original string. If so, return the original string. If not, traverse the string and count the unique characters and their frequency. concatenate them into anew string.
【时间复杂度】O(n+k^2) n is the length og the original string, k is the number of unique characters in the original string
【空间复杂度】O(k)
【gist link] https://github.com/StephenWeiXu/ ... blob/master/1_5.cpp
【test case】(optional,如果觉得比较好,欢迎贴出来分享)
https://github.com/StephenWeiXu/ ... blob/master/1_5.cpp

评分

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

查看全部评分

回复

使用道具 举报

全局:
【解题思路】
* When we want to add something to a string constantly and without knowing the total length,
* StringBuilder is a good choice.
* We check whether the adjacent elements are same. if so, we increase count number; if not, we output the count number,
* new character and reset the count number to 1.
* Please be aware that at the end, we cannot detect the different adjacent elements, but we still need to add the count number.

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

评分

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

查看全部评分

回复

使用道具 举报

🔗
sevenwonder 2015-4-6 10:57:52 | 只看该作者
全局:
【解题思路】
扫一遍如果相同count++,如果不同,count重置为1,同时把之前的count append到之前的字符后。

【时间复杂度】
O(n)
【空间复杂度】
O(n)
【gist link]
https://gist.github.com/songpu2015617/7b1e335600a5e5986518

评分

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

查看全部评分

回复

使用道具 举报

🔗
daphne_ying 2015-4-6 12:34:48 | 只看该作者
全局:

[solution]
scan the string, use a prev value and a counter to keep track of the repeat of a char, and then update the compressed string accordingly.
[time]
O(n)
[space]
O(n)
[gist]
https://gist.github.com/kelly-us/b1777dc1dc582cf253ad

评分

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

查看全部评分

回复

使用道具 举报

🔗
beer 2015-4-6 21:01:18 | 只看该作者
全局:
【解题思路】
Tips:
* Use two pointer to make the begin of repeat String snippet and current char, and
* a counter to mark the num of the repeat String snippet
【时间复杂度】O(N)
【空间复杂度】O(N)
【gist link】https://github.com/drinkbeer/Cod ... /src/CC150_1_5.java
【test case】

评分

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

查看全部评分

回复

使用道具 举报

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

本版积分规则

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