Python | Easy
see the Successfully Accepted Submission\n\n# Code\n\nclass Solution(object):\n    def minPatches(self, nums, n):\n        ans = 0\n        sum_val = 1\n       
[see the Successfully Accepted Submission](https://leetcode.com/problems/patching-array/submissions/1289786216/?envType=daily-question&envId=2024-06-16)\n\n# Code\n```\nclass Solution(object):\n    def minPatches(self, nums, n):\n        ans = 0\n        sum_val = 1\n        m = len(nums)\n        i = 0\n\n        while sum_val <= n:\n            if i < m and nums[i] <= sum_val:\n                sum_val += nums[i]\n                i += 1\n            else:\n                sum_val += sum_val\n                ans += 1\n        \n        return ans\n```\n\n![image](https://assets.leetcode.com/users/images/b1e4af48-4da1-486c-bc97-b11ae02febd0_1696186577.992237.jpeg)
['Python3']