-
1046. Last Stone WeightAlgorithm/python tip 2021. 3. 2. 11:08
leetcode.com/problems/last-stone-weight/
class Solution(object): def lastStoneWeight(self, stones): while len(stones) > 1: stones.sort(reverse=True) stones.append(abs(stones[0] - stones[1])) stones.pop(0) stones.pop(0) return stones[0]
leetcode.com/problems/last-stone-weight/discuss/576384/Python-solution.-Simplest-.2-line
class Solution: def lastStoneWeight(self, stones: List[int]) -> int: while len(stones) > 1: stones.append(stones.pop(stones.index(max(stones))) - stones.pop(stones.index(max(stones)))) return stones[0]
'Algorithm > python tip' 카테고리의 다른 글
807. Max Increase to Keep City Skyline (0) 2021.03.02 [programmers] 스택/큐 - 기능개발 (0) 2021.03.02 1588. Sum of All Odd Length Subarrays (0) 2021.03.01 1732. Find the Highest Altitude (0) 2021.03.01 1679. Max Number of K-Sum Pairs (0) 2021.03.01