Back to Browse

Last Stone Weight - LeetCode 1046 - Python Solution

43 views
Apr 24, 2023
8:04

Solution Blog: (sign into leetcode to view) - https://leetcode.com/problems/last-stone-weight/solutions/3451970/intuitive-python-solution-solution-blog/ Negate the values to be able to convert python's minHeap to maxHeap. Keep playing the game while you have more than one stone in your heap. With every iteration pop the top two weights from the heap. If the top two weights don't match, put the difference of their weights back on the heap. At the end if there's nothing left on the heap return 0, otherwise return the remaining weight. - Time complexity: O(nlogn) heapify complexity - Space complexity: O(n) for the max_heap Hope this helped - have an awesome day! #leetcode #python #tutorial

Download

1 formats

Video Formats

360pmp412.2 MB

Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.

Last Stone Weight - LeetCode 1046 - Python Solution | NatokHD