0%

LeetCode-344

题目

结果

代码

1
2
3
4
5
6
7
8
9
10
11
12
class Solution {
public void reverseString(char[] s) {
int left = 0, right = s.length - 1;
while (left < right) {
char tmp = s[left];
s[left] = s[right];
s[right] = tmp;
left++;
right--;
}
}
}

复杂度

时间复杂度:O(n)

空间复杂度:O(1)