Skip to content

Instantly share code, notes, and snippets.

@ceth-x86
Created January 17, 2021 08:30
Show Gist options
  • Save ceth-x86/f898d2c218931fa106c039b7902f2ae1 to your computer and use it in GitHub Desktop.
Save ceth-x86/f898d2c218931fa106c039b7902f2ae1 to your computer and use it in GitHub Desktop.
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