일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 10분
- Writing
- 읽기
- 뭐든
- 만화도
- 링피트
- leetcode
- 쓰릴오브파이트
- FIT XR
- 영어원서읽기
- 괜찮음
- Daily Challenge
- realclass
- 운동
- Problem Solving
- 화상영어
- 잡생각
- 3줄정리
- 매일
- 리얼 클래스
- English
- 개발자
- 30분
- 월간
- 미드시청
- 프로젝트
- 파비최
- 스탭퍼
- 영어공부
- 사이드
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.04.25 Today's Challenge 본문
https://leetcode.com/problems/last-stone-weight/
Last Stone Weight - LeetCode
Can you solve this real interview question? Last Stone Weight - You are given an array of integers stones where stones[i] is the weight of the ith stone. We are playing a game with the stones. On each turn, we choose the heaviest two stones and smash them
leetcode.com
최대 힙으로 푸는 문제!
class Solution:
def lastStoneWeight(self, stones: List[int]) -> int:
mh = [-stone for stone in stones]
heapq.heapify(mh)
while len(mh) > 1:
stone1 = heapq.heappop(mh)
stone2 = heapq.heappop(mh)
if stone1 != stone2:
heapq.heappush(mh, stone1 - stone2)
if mh:
return -mh[0]
return 0
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.04.27 Today's Challenge (0) | 2023.04.27 |
---|---|
2023.04.26 Today's Challenge (0) | 2023.04.26 |
2023.04.24 Today's Challenge (0) | 2023.04.24 |
2023.04.23 Today's Challenge (1) | 2023.04.23 |
2023.04.22 Today's Challenge (0) | 2023.04.22 |
Comments