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

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

🔗
season 2013-3-6 12:01:20 | 只看该作者
全局:
回复

使用道具 举报

🔗
edussx 2013-3-9 03:54:06 | 只看该作者
全局:
继续补作业……这题不难但是edge case好多……

https://gist.github.com/edussx/00ac748d59b91e6550b9

回复

使用道具 举报

🔗
butzhang 2013-4-21 21:59:13 | 只看该作者
全局:
In my opion,the key question lies on HOW you handle the end of the word.
https://gist.github.com/butzhang/5429660
回复

使用道具 举报

🔗
voiding 2013-5-30 12:44:35 | 只看该作者
全局:
https://gist.github.com/mogutou1214/5675756

做这个题目的时候不知道如何从int 转成string。 网上查了之后学到用ostringstream来转。用C++实现。
回复

使用道具 举报

🔗
MrKeke 2013-6-20 20:17:52 | 只看该作者
全局:
Step1: Scan the string from left to right
Step2: Check the two neighbor characters, if they are not the same, save the new previous character and its count number to the new string, otherwise, count plus 1, default count is 1
Step3: After scan, add the last character in the string and its count number.
Done !
https://gist.github.com/yaoqimin2013/5822250
回复

使用道具 举报

🔗
冰点 2013-12-27 02:18:16 | 只看该作者
全局:
这道题我有个疑问,就是答案最后不用stringBuffer的那个solution。我觉得依然是o(n^2)的runtime。因为循环中调用的setChar()依然有一个for loop。请哪位大神讲解明示一下,为什么runtime还是o(n)呢?
回复

使用道具 举报

🔗
账单大门 2013-12-28 17:37:30 | 只看该作者
全局:
此算法题的PHP源代码:
<?php
$original = "aabcccccaaa";
$strarr = str_split($original);
for ($i=0;$i<strlen($original);$i++){
        if ($i==0){
                $result[0]["letter"]=$strarr[0];
                $result[0]["count"] = 1;
        }else{
                $resarrcount = count($result);
                if ($strarr[$i]!=$strarr[$i-1]){
                        $result[$resarrcount]["letter"]=$strarr[$i];
                        $result[$resarrcount]["count"] = 1;
                }else{
                        $result[$resarrcount-1]["count"] = $result[$resarrcount-1]["count"] + 1;
                }
        }

}


$res = "";
foreach ($result as $r){
        $res =  $res.$r["letter"].$r["count"];
}

if (strlen($res)>strlen($original)){
        echo $original;
}else{
        echo $res;
}
?>
回复

使用道具 举报

🔗
账单大门 2013-12-28 19:50:46 | 只看该作者
全局:
https://github.com/cui-lei/cui-lei-PHP/commit/d4af0142d795d88c6df9672d435ca28f80a5960b
回复

使用道具 举报

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

本版积分规则

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