๋ฌธ์
ํ์ด ๊ณผ์
in place
ํ ๋ฐฉ๋ฒ์ผ๋ก ๋ฐฐ์ด์ ๋ค์ง๋ ์ฐ์ฐ์ ์ํํ๋ ๋ฌธ์ ์
๋๋ค. ์ผ์ชฝ ๋
๊ณผ ์ค๋ฅธ์ชฝ ๋
์ ๊ฐ๋ฆฌํค๋ ๋ ๊ฐ์ ํฌ์ธํฐ๋ฅผ ํ์ฉํด์ ๋ค์ง๊ธฐ ์ฐ์ฐ์ ์ํํ๋ฉด ๋ฉ๋๋ค.
์ฝ๋
/**
* @param {character[]} s
* @return {void} Do not return anything, modify s in-place instead.
*/
var reverseString = function (s) {
let lo = 0;
let hi = s.length - 1;
while (lo < hi) {
[s[hi], s[lo]] = [s[lo], s[hi]];
lo += 1;
hi -= 1;
}
return s;
};
๋ฐ์ํ
'๐ algorithm > leetcode' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
LeetCode 38 - Count and Say (Medium) (0) | 2021.04.13 |
---|---|
LeetCode 199 - Binary Tree Right Side View (Medium) (0) | 2021.04.05 |
LeetCode 1578 - Minimum Deletion Cost to Avoid Repeating Letters (Medium) (0) | 2021.03.08 |
LeetCode 904 - Fruit Into Baskets (Medium) (0) | 2021.03.08 |
LeetCode 112 - Path Sum (Easy) (0) | 2021.03.04 |
๐ฌ ๋๊ธ