Greedy solution in Python
I used a greedy algorithm. When traversing through the given number list, consider each number as a goal and resource. When in the for loop for the ith number, 
I used a greedy algorithm. When traversing through the given number list, consider each number as a **goal** and **resource**. When in the for loop for the *ith* number, try to add some numbers so that you can represent every number in the range [ 1, nums[i] ). Then, add the *ith* number to your source for further loops. \n\nTo reach the goal, suppose all the resource (the numbers smaller than the goal) sums to a number `sum`, then, `sum+1` is what we don't have. So we need to add a `sum+1` to our resource. And now you can represent all the numbers not bigger than `sum+sum+1`.\n\n    class Solution(object):\n\n    def minPatches(self, nums, n):\n        """\n        :type nums: List[int]\n        :type n: int\n        :rtype: int\n        """\n        count = 0\n        sum = 0\n        for x in nums:\n            if sum >= n:\n                return count\n            while sum < x-1:  # x-1 is the goal; when reaches the goal, we can represent [1, x)\n                count += 1\n                sum += sum + 1  # add a resource number\n                if sum >= n:\n                    return count\n            sum += x\n        while sum + 1 <= n:\n            count += 1\n            sum += sum + 1\n        return count
[]