File tree 4 files changed +66
-1
lines changed
4 files changed +66
-1
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {string } s
3
+ * @return {boolean }
4
+ */
5
+ const isPalindrome = ( s ) => {
6
+ // process the string to trim &
7
+ // gpt why what is this fking regex
8
+ s = s . replace ( / [ ^ a - z A - Z 0 - 9 ] + / g, '' ) . trim ( ) . toLowerCase ( ) ;
9
+ //s= s.replace(/[a-zA-z]/g);
10
+ console . log ( s )
11
+ // for (let i = 0; i < s.length; i++) {
12
+
13
+ let l = 0 , r = s . length - 1 ;
14
+
15
+ while ( l <= r ) {
16
+
17
+ if ( s [ l ] !== s [ r ] ) {
18
+ return false ;
19
+ }
20
+
21
+ l ++ ;
22
+ r -- ;
23
+ }
24
+
25
+ return true ;
26
+ }
27
+
28
+ // let x = isPalindrome("A man, a plan, a canal: Panama")
29
+ // let x = isPalindrome("A man, a plan, a canal: Panama")
30
+ let x = isPalindrome ( "0P" )
31
+ console . log ( "result" )
32
+ console . log ( x )
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {string } s
3
+ * @return {boolean }
4
+ */
5
+ const isPalindrome = ( s ) => {
6
+ s = s . replace ( / [ ^ a - z A - Z 0 - 9 ] + / g, '' ) . trim ( ) . toLowerCase ( ) ;
7
+ let l = 0 , r = s . length - 1 ;
8
+
9
+ while ( l <= r ) {
10
+ if ( s [ l ] !== s [ r ] ) return false ;
11
+
12
+ l ++ ;
13
+ r -- ;
14
+ }
15
+
16
+ return true ;
17
+ }
Original file line number Diff line number Diff line change 30
30
- [ 76. Minimum Window Substring] ( ./76/ )
31
31
- [ 83. Remove Duplicates from Sorted List] ( ./83/ )
32
32
- [ 121. Best Time to Buy and Sell Stock] ( ./121/ )
33
+ - [ 125. Valid Palindrome] ( ./125/ )
33
34
- [ 141. Linked List Cycle] ( ./141/ )
34
35
- [ 143. Reorder List] ( ./143/ )
35
36
- [ 152. Maximum Product Subarray] ( ./152/ )
@@ -81,5 +82,5 @@ Batch create in bash
81
82
TODO: Add to TOC!
82
83
-->
83
84
``` ssh
84
- chapter=76 && mkdir ./$chapter && touch ./$chapter/my_solution.js && touch ./$chapter/solution.js && alias x="node ./$chapter/my_solution.js"
85
+ chapter=125 && mkdir ./$chapter && touch ./$chapter/my_solution.js && touch ./$chapter/solution.js && alias x="node ./$chapter/my_solution.js"
85
86
```
Original file line number Diff line number Diff line change @@ -5,3 +5,18 @@ if (obj["a"]) {
5
5
} else {
6
6
console . log ( "n" )
7
7
}
8
+
9
+
10
+
11
+ function extractWords ( str ) {
12
+ // replace(/[^\p{L}\s]/gu, '').replace(/\s+/g, ' ').trim()
13
+ // return str.replace(/[^a-zA-Z\s]/g, '').replace(/\s+/g, ' ').trim();
14
+ return str . replace ( / [ ^ a - z A - Z ] + / g, '' ) . trim ( ) ;
15
+ return str . replace ( / [ ^ a - z A - Z \s ] + / g, ' ' ) . trim ( ) ;
16
+
17
+ }
18
+
19
+
20
+ // let str ="qw1 19jod12901j2@J(!@#"
21
+ let str = "A man, a plan, a canal: Panama" ;
22
+ console . log ( extractWords ( str ) ) ;
You can’t perform that action at this time.
0 commit comments