1046. 最后一块石头的重量
class Solution:
def lastStoneWeight(self, stones: List[int]) -> int:
q = []
for s in stones:
heappush(q, -s)
while q:
if len(q) == 1: return -q[0]
a, b = heappop(q), heappop(q)
if a != b: heappush(q, -abs(a-b))
return 0
文章来源地址https://uudwc.com/A/vmpLg
文章来源:https://uudwc.com/A/vmpLg