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

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

🔗
林微熙 2014-6-17 02:01:22 | 只看该作者
全局:
【解题思路】
traverse the string, find the end.swap from beginning until they meet in the middle
【时间复杂度】
  O(N)
【空间复杂度】
  O(1)
【gist link】https://gist.github.com/hilda8519/83237bb94060d14ab83f
回复

使用道具 举报

🔗
zhenzhenanan 2014-6-17 06:37:17 | 只看该作者
全局:
【解题思路】
用strlen获取字符串长度。用i和j两个lindex,其中i在0位置;j在len-1位置。i和j相互靠近并调换所指向的字符,直到i和j相遇。这个过程中,'\0'一直在len位置没动,所以程序结束后还是在len位置。
【时间复杂度】
O(n)
【空间复杂度】
O(1)
【gist link】
https://gist.github.com/seemuch/af64b140e576b6ea73ad#file-1_2-cc
---------------OPTional,如果觉得test case比较好,欢迎写出来分享----------------------
【test case】
回复

使用道具 举报

🔗
jyh橘子 2014-6-17 08:47:46 | 只看该作者
全局:
【解题思路】I use two pointers for the head and tail of the string, swap the two elements , move pointers forward and backward, swap until two pointers meet.
【时间复杂度】
O(n)
【空间复杂度】
O(1)
【gist link】
https://gist.github.com/jyhjuzi/4f26f7112cf58d9fcd2d
回复

使用道具 举报

🔗
RealityPC 2014-6-17 10:52:08 | 只看该作者
全局:
【解题思路】two iterator at the begin and end of string, swap chars and move the iterator until begin is equal or greater than end
【时间复杂度】O(n)
【空间复杂度】O(1)
【gist link】https://gist.github.com/pchong90/e48b4175b82883e62780
回复

使用道具 举报

🔗
chouclee 2014-6-17 11:47:27 | 只看该作者
全局:
【解题思路】two pointers, one points to first char, the other traverses to the end of the string.  Swap the elements they are pointing to. Then first pointer points to next char while the last one points to previous char. This process repeats until two pointers cross.
【时间复杂度】O(n)
【空间复杂度】O(1)
【gist link】https://gist.github.com/chouclee/bd4d1f0292c7111bbe74
回复

使用道具 举报

🔗
fang_wu 2014-6-17 17:48:45 | 只看该作者
全局:
【解题思路】java实现,先把string转换为char数组,然后跟二分法一样,维持left和right两个。一个++,一个--
【时间复杂度】O(n)
【空间复杂度】O(1)
【gist link】https://gist.github.com/qiangusc/4b705d25103a944d74e1
回复

使用道具 举报

🔗
bitcpf 2014-6-17 23:36:13 | 只看该作者
全局:
【解题思路】exchange the content of the first 1/2 and the last 1/2
【时间复杂度】O(n)
【空间复杂度】O(1)
【gist link】https://gist.github.com/bitcpf/4 ... ca0#file-cc1_2-java

点评

咱们解法其实是一样的~ 不过你的for loop...看着有点辛苦。。  发表于 2014-6-18 00:53
回复

使用道具 举报

🔗
jaly50 2014-6-18 00:51:46 | 只看该作者
全局:
【解题思路】
用java写的,不是用c++.不知道还有没有意义。
嗯,就是字符串先转成StringBuffer或者char[],再将左半部分的字符和右半部分的字符互换..
swap(s[low=0],s[high=length-1]),再low++; high--
【时间复杂度】
o(n)
【空间复杂度】
o(1)
【gist link】
https://gist.github.com/jaly50/a8a7c47a6acfffdc0381
---------------OPTional,如果觉得test case比较好,欢迎写出来分享----------------------
【test case】

点评

确实是while loop比较好。。。  发表于 2014-6-18 00:58
回复

使用道具 举报

🔗
asdw3276 2014-6-18 01:18:11 | 只看该作者
全局:

【解题思路】java实现,遍历一遍。新建了一个string,和tochararray的效果应该是一样的吧。因为java没法直接改原string。
【时间复杂度】O(n)
【空间复杂度】O(1)
【gist link】https://gist.github.com/asdw3276/39b2a443c62773fca357

感谢所有给我code review的小伙伴

点评

你这样写也不错,从字符串的最后一个字符从后往前添字符~觉得这两次的题主要还是在考字符的处理吧~  发表于 2014-6-18 10:51
我是你楼上,你咋不review我的呀~  发表于 2014-6-18 10:50
回复

使用道具 举报

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

本版积分规则

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