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

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

🔗
iker01 2015-4-1 11:36:22 | 只看该作者
全局:
【解题思路】
using the python slice syntax
【时间复杂度】
O(n)
【空间复杂度】

【gist link]
https://gist.github.com/zhangjiang2013/6aff9faadfabcf7ede2a
【test case】(optional,如果觉得比较好,欢迎贴出来分享)

评分

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

查看全部评分

回复

使用道具 举报

🔗
iker01 2015-4-1 11:36:27 | 只看该作者
全局:
本帖最后由 iker01 于 2015-4-1 12:48 编辑

【解题思路】
using the python slice syntax
【时间复杂度】
O(n)
【空间复杂度】
O(1)
【gist link]
https://gist.github.com/zhangjiang2013/6aff9faadfabcf7ede2a
【test case】(optional,如果觉得比较好,欢迎贴出来分享)
回复

使用道具 举报

🔗
Godbless 2015-4-1 12:09:10 | 只看该作者
全局:
【解题思路】Iterate from the begining to the end, replace the begining with the end for each iteration, and check the boundary case
【时间复杂度】O(n)
【空间复杂度】O(1)
【gist link]
https://github.com/StephenWeiXu/ ... blob/master/1_2.cpp
【test case】(optional,如果觉得比较好,欢迎贴出来分享)
https://github.com/StephenWeiXu/ ... blob/master/1_2.cpp

评分

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

查看全部评分

回复

使用道具 举报

🔗
outtime 2015-4-1 18:13:41 | 只看该作者
全局:
【解题思路】
two pointers, one from the begin, one from the end, swap them till they meet in the middle;
【时间复杂度】
O(n)
【空间复杂度】
O(1)
【gist link]
https://gist.github.com/seeeking/80b451eedd44e5b3f466
【test case】(optional,如果觉得比较好,欢迎贴出来分享)

评分

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

查看全部评分

回复

使用道具 举报

🔗
chongtianzs 2015-4-2 06:18:52 | 只看该作者
全局:
【解题思路】
用两个指针记录待交换的两个char,交换它们直到两个指针相遇。
【时间复杂度】
O(n)
【空间复杂度】
O(1)
【gist link]
https://gist.github.com/chongtianzs/ade26760d54dddb614a6
【test case】(optional,如果觉得比较好,欢迎贴出来分享)

评分

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

查看全部评分

回复

使用道具 举报

🔗
芒果舞 2015-4-3 09:04:24 | 只看该作者
全局:
【解题思路】
c语言,char指针来对字符串进行操作,先找到尾指针,然后前后in place交换。
【时间复杂度】
O(N)
【空间复杂度】
O(1)
【gist link】
https://gist.github.com/LinyinWu/a8fc47eef2993e3bc749
【test】
hello
        (空)
hello world

评分

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

查看全部评分

回复

使用道具 举报

🔗
beer 2015-4-3 14:54:20 | 只看该作者
全局:
【解题思路】
Tips:
* 1. Use Java API StringBuffer to reverse String Object
* 2. Convert String to char[] and swap each char
【时间复杂度】O(N)
【空间复杂度】O(N)
【gist link】https://github.com/drinkbeer/Cod ... er/src/CC150_2.java
【test case】

评分

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

查看全部评分

回复

使用道具 举报

🔗
daphne_ying 2015-4-3 15:13:05 | 只看该作者
全局:
【解题思路】
Use two pointers to indicate the positions of the char needed to be swaped
【时间复杂度】O(N)
【空间复杂度】O(1)
【gist link】https://gist.github.com/kelly-us/b199e98ae9ea9c9a7875
【test case】

评分

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

查看全部评分

回复

使用道具 举报

🔗
Fiona杀G 2015-4-5 22:14:44 | 只看该作者
全局:
#include <iostream>
#include <stdlib.h>
#include <string>

using namespace std;

/*
[question]

1.2 Implement a function void reverse(char* str) in C or C++ which reverses a nullterminated string.

[solution]
use two pointers, one in the head another in the tail,
exchange the head and the tail element, head++ tail--
until when tail is smaller or euqal to head, then the loop can stop

[time complexity]
O(n)
scan every char in the string

[space complexity]
O(1)
we do this in place, so no extra space

[gist link]
https://gist.github.com/FionaT/a428c955bb145320ac0d

[test case]

*/

void reverse_str(char *str)
{
        int len = 0;
        char *p = str, temp;
       
        while(*p != NULL){
                p++;
                len++;
        }
       
        for(int i = 0, j = len - 1; i < j; i++, j--){
                temp = str[i];
                str[i] = str[j];
                str[j] = temp;
        }
       
}

int main()
{
        char str[] = "";
       
        reverse_str(str);
       
        cout<<str<<endl;
       
        return 0;
}

评分

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

查看全部评分

回复

使用道具 举报

全局:
最后一天交作业啦

【解题思路】
* We used a temp variable to exchange the i character with leng-1-i character
* One way to do this is our method
* char[] chars = str.toCharArray();
* String newStr = String.valueOf(chars);
*
* We can also use Stringbuilder to change a character in a string
* StringBuilder myName = new StringBuilder("domanokz");
* myName.setCharAt(4, 'x');

【时间复杂度】
O(n)
【空间复杂度】
O(1)
【gist link]
https://gist.github.com/leonw007/4b1b10602e38f2e6b6c9

【test case】included in the above link

评分

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

查看全部评分

回复

使用道具 举报

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

本版积分规则

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