Skip to content

Commit f88cc36

Browse files
committed
valid palindrome solution
1 parent b2d8c3d commit f88cc36

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
ย (0)