Skip to content

Commit e27db88

Browse files
committed
sync
1 parent e7a44b6 commit e27db88

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed
Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
1-
from typing import List, Optional
2-
from functools import cache
1+
import heapq
2+
from typing import List
3+
34

45
# leetcode submit region begin(Prohibit modification and deletion)
56
class Solution:
67
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+
825
# leetcode submit region end(Prohibit modification and deletion)
926

1027

1128
class FindScoreOfAnArrayAfterMarkingAllElements(Solution):
12-
pass
29+
pass

0 commit comments

Comments
 (0)