문제 링크 : https://leetcode.com/problems/last-stone-weight/
주어진 stones배열에서 가장 큰 수-가장 작은 작은 수 의 값을 계속 계산한다.
그리고 마지막값을 반환한다.
갠적으로 heapq연습하기 좋은 문제.. 라고 생각
class Solution:
def lastStoneWeight(self, stones: List[int]) -> int:
stones = [-s for s in stones ]
heapq.heapify(stones)
while len(stones)>1:
fst= heapq.heappop(stones)
snd = heapq.heappop(stones)
if snd > fst:
heapq.heappush(stones, fst-snd)
stones.append(0)
return abs(stones[0])
22.10.07 복습