Write a function that reverses a string. The input string is given as an array of characters s.
Input: s = ["h","e","l","l","o"]
Output: ["o","l","l","e","h"]
Input: s = ["H","a","n","n","a","h"]
Output: ["h","a","n","n","a","H"]
/**
* @param {character[]} s
* @return {void} Do not return anything, modify s in-place instead.
*/
var reverseString = function(s) {
let low = 0;
let high = s.length - 1;
let save;
while (low < high) {
save = s[high];
s[high] = s[low];
s[low] = save;
high--;
low++;
}
return s;
};
이제 two pointers를 사용해 알고리즘을 푸는 건 많이 익숙해진 것 같다!