LeetCode One Question of the Day (35) 344. Reverse String (Easy)

344. Reverse String


Insert picture description here

class Solution {
    
    
public:
    void reverseString(vector<char>& s) {
    
    
        // 直接前后交换就好了,start++前进,end--后退
        if(s.size()==0) return;
        int start=0,end=s.size()-1;
        char temp;
        while(start<end){
    
    
            temp=s[start];
            s[start]=s[end];
            s[end]=temp;
            start++;
            end--;
        }
    }
};

Insert picture description here


Guess you like

Origin blog.csdn.net/qq_45021180/article/details/108966436