Skip to content

Commit 4702c0a

Browse files
committed
solve valid-palindrome
1 parent 5bdb0aa commit 4702c0a

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

valid-palindrome/1lsang.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
function isPalindrome(s: string): boolean {
2+
// console.log('A'.charCodeAt(0), 'Z'.charCodeAt(0)); // 65 90
3+
// console.log('a'.charCodeAt(0), 'z'.charCodeAt(0)); // 97 122
4+
// console.log('0'.charCodeAt(0), '9'.charCodeAt(0)); // 48 57
5+
6+
// 문자열 변환 과정
7+
let converted = ''
8+
for (let c of s) {
9+
const charCode = c.charCodeAt(0);
10+
if (charCode >= 65 && charCode <= 90) {
11+
converted += c.toLowerCase();
12+
}
13+
else if ((charCode >= 97 && charCode <= 122) || (charCode >= 48 && charCode <= 57)) {
14+
converted += c;
15+
}
16+
}
17+
18+
// palindrome 판단 조건
19+
const length = converted.length;
20+
21+
for (let i = 0; i < length/2; i ++) {
22+
if (converted[i] !== converted[length - 1 - i]) return false;
23+
}
24+
25+
return true;
26+
};

0 commit comments

Comments
 (0)