Skip to content

Commit ee72461

Browse files
committed
feat: valid-palindrome solution
1 parent c60b5f5 commit ee72461

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

valid-palindrome/YeomChaeeun.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* palindrom: 회문, 거꾸로 읽어도 제대로 읽는 것과 같은 문장
3+
* @param s
4+
*/
5+
function isPalindrome(s: string): boolean {
6+
let word = s.toLowerCase();
7+
const reg = /[\{\}\[\]\/?.,;:|\)*~`!^\-_+<>@\#$%&\\\=\(\'\" ]/g;
8+
9+
word = word.replace(reg, '');
10+
for(let i = 0; i < word.length; i++) {
11+
for(let j = word.length-i-1; j >= word.length-i-1; j--) {
12+
// console.log(word[i], '===', word[j])
13+
if(word[i] !== word[j]) return false;
14+
}
15+
}
16+
return true;
17+
};

0 commit comments

Comments
 (0)