File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed
src/inflearn_coding_test/basic Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ function solution ( str ) {
2+ const newStr = str . toLowerCase ( ) ;
3+ let isPalindrome = false ;
4+
5+ for ( let i = 0 ; i < newStr . length / 2 ; i ++ ) {
6+ if ( newStr [ i ] !== newStr [ newStr . length - i - 1 ] ) {
7+ isPalindrome = false ;
8+ return isPalindrome ;
9+ } else {
10+ isPalindrome = true ;
11+ }
12+ }
13+
14+ return isPalindrome ;
15+ }
16+
17+ console . log ( solution ( 'gooG' ) ) ; // true
18+ console . log ( solution ( 'aba' ) ) ; // true
19+ console . log ( solution ( 'abca' ) ) ; // false
Original file line number Diff line number Diff line change 1+ function solution ( str ) {
2+ const newStr = str . toLowerCase ( ) . replace ( / [ ^ a - z ] / g, '' ) ;
3+ let isPalindrome = false ;
4+
5+ for ( let i = 0 ; i < newStr . length / 2 ; i ++ ) {
6+ if ( newStr [ i ] !== newStr [ newStr . length - i - 1 ] ) {
7+ isPalindrome = false ;
8+ return isPalindrome ;
9+ } else {
10+ isPalindrome = true ;
11+ }
12+ }
13+
14+ return isPalindrome ;
15+ }
16+
17+ console . log ( solution ( 'found7, time: study; Yduts; emit, 7Dnuof' ) ) ; // YES
18+ console . log ( solution ( 'sungminkim' ) ) ; // NO
You can’t perform that action at this time.
0 commit comments