Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a969646

Browse filesBrowse files
Create 907.py
1 parent 227b80f commit a969646
Copy full SHA for a969646

File tree

1 file changed

+12
-0
lines changed
Filter options

1 file changed

+12
-0
lines changed

‎501-1000/907.py

Copy file name to clipboard
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution:
2+
def sumSubarrayMins(self, arr: List[int]) -> int:
3+
ans = 0
4+
stack = []
5+
arr = [float('-inf')] + arr + [float('-inf')]
6+
for i, n in enumerate(arr):
7+
while stack and arr[stack[-1]] > n:
8+
cur = stack.pop()
9+
ans += arr[cur] * (i - cur) * (cur - stack[-1])
10+
stack.append(i)
11+
return ans % (10**9 + 7)
12+

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.