一刷 06/2022
Version #1 Two Pointers 06/2022
Time O(N)
Space O(1)
Runtime: 1 ms, faster than 99.71% of Java online submissions for Reverse String.
Memory Usage: 58.2 MB, less than 10.28% of Java online submissions for Reverse String.
class Solution {
public void reverseString(char[] s) {
int start = 0, end = s.length - 1;
while (start < end) {
char c = s[start];
s[start] = s[end];
s[end] = c;
start++;
end--;
}
}
}
No comments:
Post a Comment