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 e603d16 commit fec6b72Copy full SHA for fec6b72
โvalid-palindrome/HerrineKim.jsโ
@@ -0,0 +1,23 @@
1
+// ์๊ฐ๋ณต์ก๋: O(n)
2
+
3
+/**
4
+ * @param {string} s
5
+ * @return {boolean}
6
+ */
7
+var isPalindrome = function (s) {
8
+ // ์ ์ฒ๋ฆฌ - ์ํ๋ฒณ๊ณผ ์ซ์๋ง ๋จ๊ธฐ๊ณ ์๋ฌธ์๋ก ๋ณํ
9
+ const cleanString = s.toLowerCase().replace(/[^a-z0-9]/g, "");
10
11
+ // ์ ๋์์ ํฌ์ธํฐ๋ฅผ ์ด๋ํ๋ฉฐ ํ์ธ
12
+ let left = 0, right = cleanString.length - 1;
13
14
+ while (left < right) {
15
+ if (cleanString[left] !== cleanString[right]) {
16
+ return false; // ๋์นญ์ด ๊นจ์ง๋ฉด false
17
+ }
18
+ left++;
19
+ right--;
20
21
22
+ return true; // ๋์นญ์ด ์ ์ง๋๋ฉด true
23
+};
0 commit comments