#leetcode344
作者:互联网
solution of leetcode344
这是我第一次用Markdown来写博客
昨天就在线写用Markdown的语法来练习了,因为我想用Markdown来完成一门公选课的期末作业,今天发现博客园支持Markdown,太爽了,以后写题解可以用Markdown来写了,这样就不用刻意去练习Markdown的语法了,今天下午攀岩没登顶,爬了四分之三,所以晚上想爆刷leetcode来弥补早上烧掉的时间,写了这道344题,一次就过了,我想看大佬是怎么写这题的,但无奈某hub有时上不去,所以我就先写题解,到时再修改,真的,追求完美不可取
试了一下显示图片的语法,又烧掉了时间,以后少发图片,尽量用英语去写题解
Hello Markdown
//This is a line of code,not a block of code,below show that my first writing code of leetcode344
class Solution {
public:
void reverseString(vector<char>& s) {
int right = 0;
int left = s.size() - 1;
while (right < left)
{
if (s[right] != s[left])
{
s[right] ^= s[left];
s[left] ^= s[right];
s[right] ^= s[left];
right++;
left--;
} else {
right++;
left--;
}
}
}
};
This is brother of wu code,look down
class Solution {
public:
string reverseString(string s) {
int i = 0, j = s.size() - 1;
while (i < j){
swap(s[i],s[j]);
i++;
j--;
}
return s;
}
};
This is Hao Chen solution
class Solution {
public:
string reverseString(string s) {
int len = s.size();
for (int i=0; i<len/2; i++) {
char ch = s[i];
s[i] = s[len-i-1];
s[len-i-1] = ch;
}
return s;
}
};
Ok,this is my first markdown blog,peace!
标签:code,string,int,leetcode344,right,Markdown,left 来源: https://www.cnblogs.com/sixiaoxiaoya/p/15695038.html