Skip to content

Commit 8937108

Browse files
committed
valid palindrome solution
1 parent eb02143 commit 8937108

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @param {string} s
3+
* @return {boolean}
4+
*
5+
* ํ•ด๊ฒฐ: ๋จผ์ € ๋ฌธ์ž์—ด์˜ ์ •๋ฐฉํ–ฅ, ์—ญ๋ฐฉํ–ฅ ๋น„๊ต๋ฅผ ์œ„ํ•ด ๋ฌธ์ž์—ด์„ ์†Œ๋ฌธ์ž๋กœ ๋ณ€ํ™˜ํ•˜์˜€์œผ๋ฉฐ ํŠน์ˆ˜๊ธฐํ˜ธ๋Š” ์ œ์™ธํ•˜์˜€์Šต๋‹ˆ๋‹ค.
6+
* ์ •๋ฐฉํ–ฅ๊ณผ ์—ญ๋ฐฉํ–ฅ์„ ๋น„๊ตํ•˜์—ฌ ๋ฌธ์ž๊ฐ€ ๋ชจ๋‘ ์ผ์น˜ํ•˜๋ฉด true ์•„๋‹ˆ๋ผ๋ฉด false๋ฅผ ๋ฐ˜ํ™˜ํ•˜์˜€์Šต๋‹ˆ๋‹ค.
7+
*/
8+
var isPalindrome = function (s) {
9+
const filterS = s.toLowerCase().replace(/[^a-z0-9]/g, "");
10+
11+
let left = 0;
12+
let right = filterS.length - 1;
13+
14+
while (left < right) {
15+
if (filterS[left] !== filterS[right]) {
16+
return false;
17+
} else {
18+
left++;
19+
right--;
20+
}
21+
}
22+
23+
return true;
24+
};

0 commit comments

Comments
ย (0)