beats 100%
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n    public int minPatches(int[] nums, int n) {\n        int i=0, patches = 0;\n        long currRange = 1L;\n        \n        while (currRange <= n) {\n            if (i < nums.length && nums[i] <= currRange) {\n                currRange += nums[i];\n                i++;\n            } else {\n                patches++;\n                currRange += currRange;\n            }\n        }\n        \n        return patches;\n    }\n}\n// if you click the upvote button you will get goodnews in 10mins\n[![Screenshot 2024-06-16 164238.jpg](https://assets.leetcode.com/users/images/baa120b8-f62b-4c8b-bee1-46e40615e949_1718537086.1983294.jpeg)]()\n![Screenshot 2024-06-16 164238.jpg](https://assets.leetcode.com/users/images/1c85d769-ec18-4903-9002-f41eb19f0ee2_1718537098.9730399.jpeg)\n\n```\n```python []\nclass Solution(object):\n    def minPatches(self, nums, n):\n        missing = 1\n        patches = 0\n        index = 0\n\n        while missing <= n:\n            if index < len(nums) and nums[index] <= missing:\n                missing += nums[index]\n                index += 1\n            else:\n                missing += missing\n                patches += 1\n\n        return patches\n\n        \n# if you click the upvote button you will get goodnews in 10mins\n```\n```C++ []\nclass Solution {\npublic:\n    int minPatches(vector<int>& nums, int n) {\n        long missing = 1;\n        int patches = 0;\n        int index = 0;\n\n        while (missing <= n) {\n            if (index < nums.size() && nums[index] <= missing) {\n                missing += nums[index];\n                index++;\n            } else {\n                missing += missing;\n                patches++;\n            }\n        }\n\n        return patches;\n    }\n};\n// if you click the upvote button you will get goodnews in 10mins\n```\n
['C++', 'Python3']