My LeetCode grinding. Trying to do a problem a day.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

problem.txt 928B

12345678910111213141516171819202122232425262728
  1. We have a collection of stones, each stone has a positive integer weight.
  2. Each turn, we choose the two heaviest stones and smash them together. Suppose the stones have weights x and y with x <= y. The result of this smash is:
  3. If x == y, both stones are totally destroyed;
  4. If x != y, the stone of weight x is totally destroyed, and the stone of weight y has new weight y-x.
  5. At the end, there is at most 1 stone left. Return the weight of this stone (or 0 if there are no stones left.)
  6. Example 1:
  7. Input: [2,7,4,1,8,1]
  8. Output: 1
  9. Explanation:
  10. We combine 7 and 8 to get 1 so the array converts to [2,4,1,1,1] then,
  11. we combine 2 and 4 to get 2 so the array converts to [2,1,1,1] then,
  12. we combine 2 and 1 to get 1 so the array converts to [1,1,1] then,
  13. we combine 1 and 1 to get 0 so the array converts to [1] then that's the value of last stone.
  14. Note:
  15. 1 <= stones.length <= 30
  16. 1 <= stones[i] <= 1000