File tree Expand file tree Collapse file tree 3 files changed +42
-1
lines changed
152-maximum-product-subarray Expand file tree Collapse file tree 3 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -70,5 +70,16 @@ https://garciparedes.me/#headers
70
70
- [x] 70
71
71
- [ ] 91
72
72
- [x] 120
73
- - [ ] 121
73
+ - [x ] 121
74
74
- [ ] 152
75
+ - [x] 198
76
+ - [ ] 264
77
+ - [ ] 279
78
+ - [ ] 300
79
+ - [ ] 303
80
+ - [ ] 309
81
+ - [ ] 322
82
+ - [ ] 338
83
+ - [ ] 343
84
+ - [ ] 357
85
+ - [ ] 376
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {number[] } nums
3
+ * @return {number }
4
+ */
5
+ var maxProduct = function ( nums ) {
6
+ let maxF = [ ...nums ] ;
7
+ let minF = [ ...nums ] ;
8
+ let res = maxF [ 0 ] ;
9
+
10
+ for ( let i = 1 ; i < nums . length ; ++ i ) {
11
+ maxF [ i ] = Math . max ( maxF [ i - 1 ] * nums [ i ] , nums [ i ] , minF [ i - 1 ] * nums [ i ] ) ;
12
+ minF [ i ] = Math . min ( minF [ i - 1 ] * nums [ i ] , nums [ i ] , maxF [ i - 1 ] * nums [ i ] ) ;
13
+ res = Math . max ( res , maxF [ i ] ) ;
14
+ }
15
+
16
+ return res ;
17
+ } ;
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {number[] } nums
3
+ * @return {number }
4
+ */
5
+ var rob = function ( nums ) {
6
+ const dp = Array ( nums . length ) . fill ( 0 ) ;
7
+
8
+ for ( let i = 0 ; i < nums . length ; i ++ ) {
9
+ dp [ i ] = Math . max ( ~ ~ dp [ i - 1 ] , ~ ~ dp [ i - 2 ] + nums [ i ] ) ;
10
+ }
11
+
12
+ return Math . max ( dp [ nums . length - 1 ] , ~ ~ dp [ nums . length - 2 ] ) ;
13
+ } ;
You can’t perform that action at this time.
0 commit comments