Skip to content

Commit 74cea70

Browse files
committed
solve: valid-palindrome 풀이
1 parent b4e34de commit 74cea70

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

valid-palindrome/reach0908.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* 시간복잡도: O(N)
3+
* 공간복잡도: O(N)
4+
* @param {string} s
5+
* @return {boolean}
6+
*/
7+
const isPalindrome = function (s) {
8+
const parsedString = s
9+
.trim()
10+
.replace(" ", "")
11+
.replace(/[^a-zA-Z0-9]/g, "")
12+
.toLowerCase();
13+
14+
let left = 0;
15+
let right = parsedString.length - 1;
16+
17+
while (left < right) {
18+
if (parsedString[left] !== parsedString[right]) {
19+
return false;
20+
}
21+
22+
left += 1;
23+
right -= 1;
24+
}
25+
26+
return true;
27+
};

0 commit comments

Comments
 (0)