#leetcode344


solution of leetcode344

这是我第一次用Markdown来写博客
昨天就在线写用Markdown的语法来练习了,因为我想用Markdown来完成一门公选课的期末作业,今天发现博客园支持Markdown,太爽了,以后写题解可以用Markdown来写了,这样就不用刻意去练习Markdown的语法了,今天下午攀岩没登顶,爬了四分之三,所以晚上想爆刷leetcode来弥补早上烧掉的时间,写了这道344题,一次就过了,我想看大佬是怎么写这题的,但无奈某hub有时上不去,所以我就先写题解,到时再修改,真的,追求完美不可取

photo

试了一下显示图片的语法,又烧掉了时间,以后少发图片,尽量用英语去写题解
Hello Markdown
Top is a line of code,not a block of code,below show that my first writing code of leetcode344
This problem let us reverse given string such as "hello" will be reverse to "olleh"

class Solution {
public:
    void reverseString(vector& s) {

        int right = 0;//pointer of head
        int left = s.size() - 1;//pointer of tail

        while (right < left)
        {//if elements of right and left are not equal,swap them
            if (s[right] != s[left])
            {
                s[right] ^= s[left];//swap two things
                s[left] ^= s[right];
                s[right] ^= s[left];
                right++;//update pointer of head
                left--;//update pointer of tail
            } 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

Ok,this is my first markdown blog,peace!

相关