We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a932317 commit 49c8750Copy full SHA for 49c8750
Last Stone Weight - Leetcode 1046/Last Stone Weight - Leetcode 1046.py
@@ -1,3 +1,22 @@
1
+# Brute Force Solution
2
+class Solution:
3
+ def lastStoneWeight(self, stones: List[int]) -> int:
4
+
5
+ def remove_largest():
6
+ index_of_largest = stones.index(max(stones))
7
+ return stones.pop(index_of_largest)
8
9
+ while len(stones) > 1:
10
+ stone_1 = remove_largest()
11
+ stone_2 = remove_largest()
12
+ if stone_1 != stone_2:
13
+ stones.append(stone_1 - stone_2)
14
15
+ return stones[0] if stones else 0
16
+# Time: O(n^2)
17
+# Space: O(1)
18
19
+# Optimal Solution
20
class Solution:
21
def lastStoneWeight(self, stones: List[int]) -> int:
22
for i in range(len(stones)):
0 commit comments