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+ const combinationSum = ( candidates , target ) => {
2+ const result = [ ] ;
3+
4+ const backtrack = ( startIndex , current , remaining ) => {
5+ if ( remaining === 0 ) {
6+ result . push ( [ ...current ] ) ;
7+ return ;
8+ }
9+ if ( remaining < 0 ) return ;
10+
11+ for ( let i = startIndex ; i < candidates . length ; i ++ ) {
12+ current . push ( candidates [ i ] ) ;
13+ backtrack ( i , current , remaining - candidates [ i ] ) ;
14+ current . pop ( ) ;
15+ }
16+ } ;
17+
18+ backtrack ( 0 , [ ] , target ) ;
19+ return result ;
20+ } ;
Original file line number Diff line number Diff line change 1+ const hammingWeight = ( n ) => n . toString ( 2 ) . split ( "" ) . filter ( b => b === "1" ) . length ;
Original file line number Diff line number Diff line change 1+ const isPalindrome = ( s ) => {
2+ const cleaned = s . toLowerCase ( ) . replace ( / [ ^ a - z 0 - 9 ] / g, '' ) ;
3+ const reversed = cleaned . split ( '' ) . reverse ( ) . join ( '' ) ;
4+ return cleaned === reversed ;
5+ } ;
You can’t perform that action at this time.
0 commit comments