Easy Python solution defeat 100%
Let\'s see a situation, for example the n is 10 and nums is empty, the optimal solution to "reach" 10 is 0 1 2 4 7 15, we can find the pattern that we start fro
Let\'s see a situation, for example the n is 10 and `nums` is empty, the optimal solution to "reach" 10 is `0 1 2 4 7 15`, we can find the pattern that we start from `stack = [0]`, the next number should be sum of stack plus 1 equal to 1, and put 1 into stack, it become [0, 1], then the next number should be 2, the stack should be [0, 1, 2]...\nThen what about if we have a 3 in nums? \n```\n1. [0]\n2. [0, 1]\n3. [0, 1, 2]\n4. [0, 1, 2, 4] # becase 4 is greater than 3 which we already have in nums, let\'s replace 4 with 3\n4. [0, 1, 2, 3]\n5. [0, 1, 2, 3, 7] # next step will reach target n=10!\n6. [0, 1, 2, 3, 7, 14]\n```\nIf current nums is >= nums[i], use nums[i] replace current number and add it into SUM until SUM is >= n.\n```\nclass Solution:\n    def minPatches(self, nums: List[int], n: int) -> int:\n        ret = i = s = 0 # ret: return value, s: SUM\n        while True:\n            if s >= n:\n                return ret\n            if i < len(nums) and s + 1 >= nums[i]:\n                s += nums[i]\n                i += 1\n            else:\n                s += s + 1\n                ret += 1\n```
['Python']