File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -55,3 +55,31 @@ var isPalindrome = function(s) {
55
55
}
56
56
return true ;
57
57
} ;
58
+
59
+ /**
60
+ * 2 Pointer | Midde Convergence | No RegEx | No Copying
61
+ * Time O(N) | Space O(1)
62
+ * https://leetcode.com/problems/valid-palindrome/
63
+ * @param {string } s
64
+ * @return {boolean }
65
+ */
66
+ var isPalindrome = function ( s ) {
67
+ const isAlpha = c => ( c . toLowerCase ( ) >= 'a' && c . toLowerCase ( ) <= 'z' ) || c >= '0' && c <= '9'
68
+
69
+ let i = 0 ;
70
+ let j = s . length - 1 ;
71
+
72
+ while ( i < j ) {
73
+ if ( ! isAlpha ( s . charAt ( i ) ) ) {
74
+ i ++
75
+ } else if ( ! isAlpha ( s . charAt ( j ) ) ) {
76
+ j --
77
+ } else if ( s . charAt ( i ) . toLowerCase ( ) !== s . charAt ( j ) . toLowerCase ( ) ) {
78
+ return false
79
+ } else {
80
+ i ++
81
+ j --
82
+ }
83
+ }
84
+ return true
85
+ } ;
You can’t perform that action at this time.
0 commit comments