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

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

全局:
【解题思路】use python way
【时间复杂度】O(n)
【空间复杂度】O(n)
【gist link】
https://gist.github.com/tangxukai/b93f4e6a33c92643bbcd
【test case
回复

使用道具 举报

🔗
Tsien 2014-6-21 23:15:51 | 只看该作者
全局:

【解题思路】
//a routine way
【时间复杂度】
O(n)
【空间复杂度】
O(1)
【gist link】
https://gist.github.com/Tsien/a39a2edf6c4535eba329
回复

使用道具 举报

🔗
七00夜 2014-6-21 23:29:39 | 只看该作者
全局:
【解题思路】
声明一个临时变量,把数组的元素前后对应位置交换赋值即可
【时间复杂度】

【空间复杂度】

【gist link】
https://gist.github.com/daf91c24b6cb2cdbba5e.git
回复

使用道具 举报

🔗
bearkino 2014-6-22 01:36:08 | 只看该作者
全局:
【解题思路】
java,转换为数组,然后前后一起往中间move,swap。或者直接用StringBuilder,for loop逆转。
【时间复杂度】
O(n)
【空间复杂度】
O(1)/O(n)
【gist link】https://gist.github.com/UncleGarden/85509dad7178cde74c50
回复

使用道具 举报

🔗
ivycheung1208 2014-6-24 02:52:16 | 只看该作者
全局:
【解题思路】
two pointers indicating characters to be swapped, traversing from front and end of the string respectively.
first use a C style index, then improved with C++ style iterator.
【时间复杂度】
O(n)
【空间复杂度】
O(1)
【gist link】
https://gist.github.com/0b07ee098f3a7e0c1889
【test case】
N/A
回复

使用道具 举报

🔗
sanguine 2014-6-24 14:38:06 | 只看该作者
全局:
写完了此题,翻了翻博客,这篇博客写的很赞:http://www.cnblogs.com/kirinboy/ ... verse-a-string.html

基本上列出了所有的方法~没想到StringBuffer是最快捷的~
回复

使用道具 举报

🔗
sanguine 2014-6-25 16:41:45 | 只看该作者
全局:
solution 1
covert the input string to the StringBuffer and fast use the reverse() method to reverse it, finally, convert back to String type.

solution 2
1. Covert the string into a char[]
2. Two pointers which point to the head and tail(not ‘\0′, but the one before it) elements of the char[]
3. swap the value of the two nodes
Time Complexity: O(n)
Space Complexity: O(n)

Solution3
using Recursion to solve this problem

Link is here: http://www.jyuan92.com/post-270
回复

使用道具 举报

🔗
whiteflower 2014-7-4 08:25:26 | 只看该作者
全局:
【解题思路】
Use two pointers: one pointing to head, and the other pointing
to tail. Move the pointers towards each other and swap the two
values step by step.
【时间复杂度】
O(n)
【空间复杂度】
O(1)
【gist link】
https://gist.github.com/JoshuaTang/c0ec657385a93265c8ed
回复

使用道具 举报

🔗
pyemma 2014-7-5 15:15:11 | 只看该作者
全局:
fang_wu 发表于 2014-6-17 17:48
【解题思路】java实现,先把string转换为char数组,然后跟二分法一样,维持left和right两个。一个++,一个- ...

使用了额外的数组不能算是O(1)空间复杂度吧
回复

使用道具 举报

🔗
fang_wu 2014-7-5 22:49:13 | 只看该作者
全局:
pyemma 发表于 2014-7-5 15:15
使用了额外的数组不能算是O(1)空间复杂度吧

额,是的,感谢哈
回复

使用道具 举报

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

本版积分规则

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