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

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

🔗
Neal 2014-6-18 08:04:30 | 只看该作者
全局:
【解题思路】Calculate the length of the string N('\0' excluded), then swap the str[0] and str[N-1], str[1] and str[N-2], ...
【时间复杂度】
O(n)
【空间复杂度】
O(1)
【gist link】
https://gist.github.com/nealhu/15b80e2e3224e30127a0
回复

使用道具 举报

🔗
rxTByjroA2h3 2014-6-18 09:46:20 | 只看该作者
全局:
本帖最后由 larry 于 2014-6-18 12:11 编辑

【解题思路】swap ith char and (len-i-1)th char
【时间复杂度】O(N)
【空间复杂度】O(1)
【gist link】https://gist.github.com/larry-liu/9d0e06ea7f6761fd32ee
---------------OPTional,如果觉得test case比较好,欢迎写出来分享----------------------
【test case】
str = malloc(256);
strcpy(str, "this is my test case");

I am not sure how to reply.... So I just write here.
It is only allowed in C99 mode to declare varible in for loop. To avoid that error message, I declare this i out of for loop.
Thanks for your reply and I think i need to compile my code in C99 mode.

点评

Instead of writing int i = 0; for(i = 0; i < (len+1)/2 ; i++), is it better to make i a loop variable: for(int i = 0; i < (len+1)/2 ; i++), it makes more sense to me.  发表于 2014-6-18 11:41
回复

使用道具 举报

🔗
heycinderella 2014-6-18 11:02:11 | 只看该作者
全局:
readman 发表于 2014-6-16 00:07
【解题思路】
same to binary search ?
【时间复杂度】

求解释:为什么空间是lgN? 和binary search有什么关系?
评论:
  if (str[i] != str[j]) {
                swap(str, i , j);
            } 这个优化很不错
回复

使用道具 举报

🔗
heycinderella 2014-6-18 11:13:21 | 只看该作者
全局:
本帖最后由 heycinderella 于 2014-6-19 11:43 编辑

啊才通过,ignore这楼
回复

使用道具 举报

🔗
grassgigi 2014-6-18 11:31:38 | 只看该作者
全局:
本帖最后由 grassgigi 于 2014-6-18 11:37 编辑

【解题思路】reverse by tracking two index pointers
【时间复杂度】O(n)
【空间复杂度】O(1)
【gist link】https://gist.github.com/chrislukkk/30dcfb00ced279778de8
回复

使用道具 举报

🔗
thevenin 2014-6-18 12:04:54 | 只看该作者
全局:
本帖最后由 thevenin 于 2014-6-18 12:34 编辑

【解题思路】I just use str.toCharArray() to convert string to char[], and get char[]'s head and tail. Then swap head++ and tail-- char until they meet together. Finally, use String.valueOf(char[] str) to convert char[] to string
【时间复杂度】
O(n)
【空间复杂度】
O(1)
【gist link】https://gist.github.com/bindai/cecfc39649fade0b5718
求解: 为啥 我的 link 没有超链接





回复

使用道具 举报

🔗
readman 2014-6-18 12:31:32 | 只看该作者
全局:
heycinderella 发表于 2014-6-18 11:02
求解释:为什么空间是lgN? 和binary search有什么关系?
评论:
  if (str != str[j]) {

..脑抽了..不好意思...
感觉和二叉搜索很像啊,
回复

使用道具 举报

🔗
southpenguin 2014-6-18 12:39:51 | 只看该作者
全局:
【解题思路】swap the first and last "char" in the "char * str" until the center of the string.
【时间复杂度】O(n)
【空间复杂度】O(1)
【gist link】https://gist.github.com/southpenguin/398170b101620d9c76f2
回复

使用道具 举报

🔗
guchang 2014-6-18 14:02:37 | 只看该作者
全局:
【解题思路】得到字符串长度L,第i个字符和L-i个字符进行交换。
【时间复杂度】O(n)
【空间复杂度】O(n)
【gist link】https://gist.github.com/guchang/2cf5ea70a893d0a118dd
回复

使用道具 举报

🔗
zZ-IT 2014-6-18 14:16:07 | 只看该作者
全局:
【解题思路】Firstly get the length of the string. and then swap the i and length-i-1 characters. But I forgot that there is a function named strlen() can get the string length. and I write that function by myself. ++!
【时间复杂度】O(n)
【空间复杂度】O(1)
【gist link】https://gist.github.com/ZhuGuanyu/83c1aedc0a485fd96d06
回复

使用道具 举报

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

本版积分规则

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