File tree Expand file tree Collapse file tree 1 file changed +21
-4
lines changed Expand file tree Collapse file tree 1 file changed +21
-4
lines changed Original file line number Diff line number Diff line change 1
- from typing import List , Optional
2
- from functools import cache
1
+ import heapq
2
+ from typing import List
3
+
3
4
4
5
# leetcode submit region begin(Prohibit modification and deletion)
5
6
class Solution :
6
7
def findScore (self , nums : List [int ]) -> int :
7
-
8
+ marked = set ()
9
+ N = len (nums )
10
+ nums_heap = [(nums [i ], i ) for i in range (N )]
11
+ heapq .heapify (nums_heap )
12
+ score = 0
13
+ while nums_heap :
14
+ s , i = heapq .heappop (nums_heap )
15
+ while nums_heap and i in marked :
16
+ s , i = heapq .heappop (nums_heap )
17
+ if i not in marked :
18
+ marked .add (i )
19
+ marked .add (i - 1 )
20
+ marked .add (i + 1 )
21
+ score += s
22
+ return score
23
+
24
+
8
25
# leetcode submit region end(Prohibit modification and deletion)
9
26
10
27
11
28
class FindScoreOfAnArrayAfterMarkingAllElements (Solution ):
12
- pass
29
+ pass
You can’t perform that action at this time.
0 commit comments