[刷题班] LeetCode344. 反转字符串

题目描述

思路:左右指针

方法一:

class Solution {
    public void reverseString(char[] s) {
        int left = 0, right = s.length - 1;
        while (left < right) {
            char temp = s[left];
            s[left] = s[right];
            s[right] = temp;
            left ++;
            right --;
        }
    }
}
posted @ 2024-01-14 15:50  Ac_c0mpany丶  阅读(2)  评论(0编辑  收藏  举报