File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /**
2+ * @param {number[] } nums
3+ * @return {number }
4+ */
5+ const maxSubArray = ( nums ) => {
6+ let currentSum = nums [ 0 ] ;
7+ let maxSum = nums [ 0 ] ;
8+
9+ for ( let i = 1 ; i < nums . length ; i ++ ) {
10+ currentSum = Math . max ( nums [ i ] , currentSum + nums [ i ] ) ;
11+ maxSum = Math . max ( maxSum , currentSum ) ;
12+ }
13+
14+ return maxSum ;
15+ } ;
Original file line number Diff line number Diff line change 1+ /**
2+ * @param {number } n
3+ * @return {number }
4+ */
5+ const hammingWeight = ( n ) => {
6+ const binary = n . toString ( 2 ) ;
7+ return binary . split ( "" ) . filter ( ( bit ) => bit === "1" ) . length ;
8+ } ;
Original file line number Diff line number Diff line change 1+ /**
2+ * @param {string } s
3+ * @return {boolean }
4+ */
5+ const isPalindrome = ( s ) => {
6+ const cleaned = s . toLowerCase ( ) . replace ( / [ ^ a - z 0 - 9 ] / g, "" ) ;
7+ const flipped = cleaned . split ( "" ) . reverse ( ) . join ( "" ) ;
8+
9+ return cleaned === flipped ;
10+ } ;
You can’t perform that action at this time.
0 commit comments