File tree Expand file tree Collapse file tree 3 files changed +43
-0
lines changed
011. Container With Most Water
926. Flip String to Monotone Increasing Expand file tree Collapse file tree 3 files changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ const maxArea2 = function ( height ) {
2
+ let result = 0 ;
3
+ for ( let i = 0 ; i < height . length ; i ++ ) {
4
+ for ( let j = i + 1 ; j < height . length ; j ++ ) {
5
+ result = Math . max ( result , Math . min ( height [ i ] , height [ j ] ) * ( j - i ) ) ;
6
+ }
7
+ }
8
+ return result ;
9
+ } ;
10
+
11
+ const maxArea = function ( height ) {
12
+ let result = 0 , l = 0 , r = height . length - 1 ;
13
+ while ( l < r ) {
14
+ result = Math . max ( result , Math . min ( height [ l ] , height [ r ] ) * ( r - l ) ) ;
15
+ height [ l ] < height [ r ] ? l ++ : r -- ;
16
+ }
17
+ return result ;
18
+ }
Original file line number Diff line number Diff line change
1
+ const hammingWeight = function ( n ) {
2
+ let result = 0 ;
3
+ while ( n ) {
4
+ result += n & 1 ;
5
+ n = n >>> 1 ;
6
+ }
7
+ return result ;
8
+ }
Original file line number Diff line number Diff line change
1
+ const minFlipsMonoIncr = function ( S ) {
2
+ let n = S . length ;
3
+ let f = [ ] ;
4
+ for ( let i = 0 ; i < n + 1 ; i ++ ) {
5
+ f . push ( 0 ) ;
6
+ }
7
+ for ( let i = 0 ; i < n ; i ++ ) {
8
+ f [ i + 1 ] = f [ i ] + ( S [ i ] === '1' ) ;
9
+ }
10
+ let ans = n ;
11
+ for ( let i = 0 ; i <= n ; i ++ ) {
12
+ let a = f [ i ] ;
13
+ let b = ( n - i ) - ( f [ n ] - f [ i ] ) ;
14
+ ans = Math . min ( ans , b + a ) ;
15
+ }
16
+ return ans ;
17
+ } ;
You can’t perform that action at this time.
0 commit comments