llllmz

导航

344. 反转字符串

 

class Solution {
public:
    void reverseString(vector<char>& s) {
        int head = 0, tail = s.size() -1;
        while(head < tail){
            char temp = s[head];
            s[head] = s[tail];
            s[tail] = temp;
            ++head;
            --tail;
        }
    }
};

 

posted on 2024-10-14 22:24  神奇的萝卜丝  阅读(2)  评论(0编辑  收藏  举报