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 b2d8c3d commit f88cc36Copy full SHA for f88cc36
1 file changed
โvalid-palindrome/seongmin36.jsโ
@@ -0,0 +1,27 @@
1
+/**
2
+s๋ฅผ ์ ๊ท์์ผ๋ก ์ํ๋ฒณ ์๋ฌธ์ string๋ง ๋จ๊ฒจ๋ฌ์ผํ๋ค.
3
+์ํ๋ฒณ ์๋ฌธ์๋ง ๋จ๊ฒจ๋๋๋ก ํ๋ ์ ๊ท์์ '/[^a-z0-9]/gi'์ด๋ค.
4
+left(0)์ right(๋ง์ง๋ง ์ธ๋ฑ์ค)๋ฅผ ๋์์ ํ๋์ฉ ์ค์ฌ๊ฐ๋ฉด์ ๋น๊ต
5
+ */
6
+
7
8
+ * @param {string} s
9
+ * @return {boolean}
10
11
+function isPalindrome(s) {
12
+ s = s.replace(/[^a-z0-9]/gi, "").toLowerCase();
13
14
+ let left = 0;
15
+ let right = s.length - 1;
16
17
+ while (left < right) {
18
+ if (s[left] !== s[right]) {
19
+ return false;
20
+ }
21
22
+ left++;
23
+ right--;
24
25
26
+ return true;
27
+}
0 commit comments