File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ # O(n) time, O(1) space
2+ # isalnum() -> 문자열이 영어, 한글 혹은 숫자로 되어있으면 참 리턴, 아니면 거짓 리턴.
3+
4+ class Solution :
5+ def isPalindrome (self , s : str ) -> bool :
6+ l = 0
7+ r = len (s ) - 1
8+
9+ while l < r :
10+ if not s [l ].isalnum ():
11+ l += 1
12+ elif not s [r ].isalnum ():
13+ r -= 1
14+ elif s [l ].lower () == s [r ].lower ():
15+ l += 1
16+ r -= 1
17+ else :
18+ return False
19+ return True
20+
Original file line number Diff line number Diff line change 1+ // O(n) time, O(1) space
2+
3+ function isPalindrome ( s : string ) : boolean {
4+ let low = 0 ,
5+ high = s . length - 1 ;
6+
7+ while ( low < high ) {
8+ while ( low < high && ! s [ low ] . match ( / [ 0 - 9 a - z A - Z ] / ) ) {
9+ low ++ ;
10+ }
11+ while ( low < high && ! s [ high ] . match ( / [ 0 - 9 a - z A - Z ] / ) ) {
12+ high -- ;
13+ }
14+ if ( s [ low ] . toLowerCase ( ) !== s [ high ] . toLowerCase ( ) ) {
15+ return false ;
16+ }
17+ low ++ ;
18+ high -- ;
19+ }
20+ return true ;
21+ }
You can’t perform that action at this time.
0 commit comments