File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 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+ } ;
You can’t perform that action at this time.
0 commit comments