Skip to content

Commit 0ea6ce8

Browse files
committed
isPalindrome 풀이 추가
1 parent 8276bc6 commit 0ea6ce8

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

valid-palindrome/junzero741.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// TC: O(n)
2+
// SC: O(1)
3+
function isPalindrome(s: string): boolean {
4+
5+
let L = 0;
6+
let R = s.length-1;
7+
8+
while(R > 0 && L < s.length - 1 && L <= R) {
9+
if(!isAlphanumeric(s[L])) {
10+
L++;
11+
continue;
12+
}
13+
if(!isAlphanumeric(s[R])) {
14+
R--;
15+
continue;
16+
}
17+
if(s[L].toLowerCase() !== s[R].toLowerCase()) {
18+
return false;
19+
}
20+
L++;
21+
R--;
22+
}
23+
24+
return true;
25+
};
26+
27+
function isAlphanumeric(str: string): boolean {
28+
return /^[a-zA-Z0-9]+$/.test(str);
29+
}

0 commit comments

Comments
 (0)