File tree 3 files changed +47
-0
lines changed
3 files changed +47
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {number } x
3
+ * @return {boolean }
4
+ */
5
+ const isPalindrome = ( x ) => {
6
+ x = x . toString ( ) ;
7
+ let length = x . length , processedNum = "#" ;
8
+
9
+ for ( let i = 0 ; i < x . length ; i ++ ) {
10
+ processedNum += x [ i ] + "#" ;
11
+ }
12
+
13
+ console . log ( length ) ;
14
+ // console.log(processedNum);
15
+ // console.log(processedNum.length);
16
+ // console.log(Math.ceil(processedNum.length / 2));
17
+
18
+ // while ()
19
+ for ( let i = 0 ; i < processedNum . length ; i ++ ) {
20
+ console . log ( `${ processedNum [ i ] } ===? ${ processedNum [ processedNum . length - 1 - i ] } ` )
21
+ if ( processedNum [ i ] !== processedNum [ processedNum . length - 1 - i ] ) return false ;
22
+ }
23
+
24
+ return true ;
25
+ } ;
26
+
27
+ let x = isPalindrome ( 121 ) ;
28
+ console . log ( x ) ;
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {number } x
3
+ * @return {boolean }
4
+ */
5
+ const isPalindrome = ( x ) => {
6
+ x = x . toString ( ) ;
7
+ let processedNum = "#" ;
8
+
9
+ for ( let i = 0 ; i < x . length ; i ++ ) {
10
+ processedNum += x [ i ] + "#" ;
11
+ }
12
+
13
+ for ( let i = 0 ; i < processedNum . length ; i ++ ) {
14
+ if ( processedNum [ i ] !== processedNum [ processedNum . length - 1 - i ] ) return false ;
15
+ }
16
+
17
+ return true ;
18
+ } ;
Original file line number Diff line number Diff line change 17
17
- [ 4. Median of Two Sorted Arrays] ( ./4/ )
18
18
- [ 5. Longest Palindromic Substring] ( ./5/ )
19
19
- [ 7. Generate Parentheses] ( ./7/ )
20
+ - [ 9. Palindrome Number] ( ./9/ )
20
21
- [ 11. Container With Most Water] ( ./11/ )
21
22
- [ 15. 3Sum] ( ./15/ )
22
23
- [ 19. Remove Nth Node From End of List] ( ./19/ )
You can’t perform that action at this time.
0 commit comments