1 Day 1 Commit Challenge!
오늘은 리트코드의 last stone weight 를 풀어보았다.
아직 파이썬에 익숙하지 않아 다양한 함수를 불러오는 데에 어려움이 많다.
Last Stone Weight - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
리트 코드의 Easy 단계의 문제들을 계속 풀어나갈 예정이다.
해답은 이렇게 ...
class Solution(object):
def lastStoneWeight(self, stones):
"""
:type stones: List[int]
:rtype: int
"""
max_heap = [-x for x in stones]
heapq.heapify(max_heap)
for i in xrange(len(stones)-1):
x,y = -heapq.heappop(max_heap), -heapq.heappop(max_heap)
heapq.heappush(max_heap, -abs(x-y))
return -max_heap[0]
*문제는 깃헙의 JSON이 제대로 동작하지 않는다.
해결방법을 아는 사람은 연락 부탁 ..
GitHub - Park-Minjoo/CODINGINTERVIEW_PRACTICE: 1 Day 1 Problem since 2022.4.7
1 Day 1 Problem since 2022.4.7. Contribute to Park-Minjoo/CODINGINTERVIEW_PRACTICE development by creating an account on GitHub.
github.com
'Programming > 1 Day 1 Commit' 카테고리의 다른 글
[Programmars] 완전탐색: 모의고사(Python3) (0) | 2022.06.15 |
---|---|
[LeetCode] 13. Romans to Integer (Python) (0) | 2022.04.09 |
[LeetCode] 9. Palindrome Number (python) (0) | 2022.04.09 |
[HackerRank] PlusMinus (python) (0) | 2022.04.09 |
[HackerRank] Diagonal Difference (python) (0) | 2022.04.07 |