File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed
Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * @param {number[] } nums
3+ * @return {number }
4+ */
5+ const maxSumMinProduct = function ( nums ) {
6+ const n = nums . length
7+ let ans = 0 ; const sum = [ ] ; let s = [ - 1 ] ; const l = [ ] ; const r = [ ]
8+ sum [ - 1 ] = 0 , nums [ - 1 ] = nums [ n ] = - 1
9+ for ( let i = 0 ; i < n ; i ++ ) {
10+ sum [ i ] = sum [ i - 1 ] + nums [ i ]
11+ while ( nums [ s [ s . length - 1 ] ] >= nums [ i ] ) s . pop ( )
12+ l [ i ] = s [ s . length - 1 ]
13+ s . push ( i )
14+ }
15+ s = [ n ]
16+ for ( let i = n - 1 ; i >= 0 ; i -- ) {
17+ while ( nums [ s [ s . length - 1 ] ] >= nums [ i ] ) s . pop ( )
18+ r [ i ] = s [ s . length - 1 ]
19+ s . push ( i )
20+ }
21+ for ( let i = 0 ; i < n ; i ++ ) {
22+ // 区间和 [l[i]+1, r[i]-1]
23+ const tmp = BigInt ( nums [ i ] ) * BigInt ( sum [ r [ i ] - 1 ] - sum [ l [ i ] ] )
24+ if ( tmp > ans ) ans = tmp
25+ }
26+ return ans % BigInt ( 1e9 + 7 )
27+ }
Original file line number Diff line number Diff line change 8585- 316 . Remove Duplicate Letters
8686- 402 . Remove K Digits
8787- 42 . Trapping Rain Water
88+ - 1856 . Maximum Subarray Min-Product
8889
8990### DP
9091
You can’t perform that action at this time.
0 commit comments