Created
January 17, 2021 08:30
-
-
Save ceth-x86/f898d2c218931fa106c039b7902f2ae1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def lastStoneWeight(self, stones: List[int]) -> int: | |
sorted_stones = list(sorted(stones)) | |
while True: | |
if len(sorted_stones) > 1: | |
x = sorted_stones[-2] | |
y = sorted_stones[-1] | |
del sorted_stones[-1] | |
del sorted_stones[-1] | |
if x != y: | |
delta = y - x | |
sorted_stones.append(delta) | |
sorted_stones = list(sorted(sorted_stones)) | |
elif len(sorted_stones) == 1: | |
return sorted_stones[0] | |
else: | |
return 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment