We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8f9850a commit d6eba78Copy full SHA for d6eba78
โvalid-palindrome/seona926.jsโ
@@ -0,0 +1,29 @@
1
+/**
2
+ * @param {string} s
3
+ * @return {boolean}
4
+ */
5
+var isPalindrome = function (s) {
6
+ // 1. ์๋ ๋ฐฉ์์ O(n^2)์ ์๋ ดํจ
7
+ // s์ ๊ตฌ์ฑ์์๋ค์ ์๋ฌธ์๋ก ๋ณํ ํ ๋ฐฐ์ด์ ๋ฃ๊ณ
8
+ // ํ์ฌ ๊ธธ์ด๊ฐ 2 ์ด์์ด๋ผ๋ฉด
9
+ // shift === pop ์ด๋ฉด true ์๋๋ฉด false
10
+
11
+ // 2. ํฌ ํฌ์ธํฐ ์ฌ์ฉ
12
13
+ let str = s.toLowerCase().replace(/[^a-z0-9]/g, "");
14
15
+ // ๋ ํฌ์ธํฐ ์ฌ์ฉ: ์์๊ณผ ๋์์๋ถํฐ ๋น๊ต
16
+ let left = 0;
17
+ let right = str.length - 1;
18
19
+ while (left < right) {
20
+ if (str[left] !== str[right]) {
21
+ return false; // ๋ ๋ฌธ์๊ฐ ๋ค๋ฅด๋ฉด palindrome ์๋
22
+ }
23
24
+ left++;
25
+ right--;
26
27
28
+ return true;
29
+};
0 commit comments