Skip to content

Commit e4a226c

Browse files
committed
solution Valid Palindrome (#220)
#220
1 parent 9e25289 commit e4a226c

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

โ€Žvalid-palindrome/jiji-hoon96.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,34 @@
1+
/**
2+
*
3+
* @param s
4+
*
5+
* ํ’€์ด 1
6+
*
7+
* ํŠน์ˆ˜๋ฌธ์ž ์ •๊ทœ ํ‘œํ˜„์‹์ด ๋ณต์žกํ•˜๊ณ , ๋ถ„ํ• ๊ณผ ํ•ฉ์น˜๋Š” ๊ณผ์ •์ด ์ค‘๋ณต๋œ๋‹ค
8+
*
9+
* function isPalindrome(s: string): boolean {
10+
* const reg= /[\{\}\[\]\/?.,;:|\)*~`!^\-_+<>@\#$%&\\\=\(\'\"]/gi;
11+
* let palindrome= s.replace(reg,'').toLowerCase().split('');
12+
*
13+
* return palindrome.join('').replace(/ /g,"")===palindrome.reverse().join('').replace(/ /g,"")
14+
* };
15+
*
16+
* ๊ทธ๋ž˜์„œ ์ƒ๊ฐํ•œ ํ’€์ด 2๋Š” s consists only of printable ASCII characters. ์„ ๋ณด๊ณ  ์ˆซ์ž์™€ ์•ŒํŒŒ๋ฒณ์„ ์ œ์™ธํ•˜๊ณ  ๋‚˜๋จธ์ง€๋Š” ์ œ๊ฑฐํ•˜๊ณ 
17+
* ํˆฌํฌ์ธํŠธ ๋ฐฉ๋ฒ•์œผ๋กœ ๋ณ€๊ฒฝํ•ด์„œ ๋ฌธ์ œ ํ•ด๊ฒฐ
18+
*/
19+
120
function isPalindrome(s: string): boolean {
21+
const cleanStr = s.toLowerCase().replace(/[^a-z0-9]/g, '');
22+
23+
let left = 0;
24+
let right = cleanStr.length-1;
225

3-
};
26+
while(left < right){
27+
if(cleanStr[left] !== cleanStr[right]){
28+
return false;
29+
}
30+
left++;
31+
right--;
32+
}
33+
return true
34+
};

0 commit comments

Comments
ย (0)