Clean and simple solution [ Java ]
Code\n\nclass Solution {\n    public int minPatches(int[] nums, int n) {\n        int minPatch = 0, i = 0, len = nums.length;\n        long currentMaxValue = 0;
# Code\n```\nclass Solution {\n    public int minPatches(int[] nums, int n) {\n        int minPatch = 0, i = 0, len = nums.length;\n        long currentMaxValue = 0;\n\n        while(currentMaxValue < n)\n        {\n            if(i < len && currentMaxValue+1 >= nums[i])\n            {\n                currentMaxValue += nums[i];\n                ++i;\n            } \n            else\n            {\n                currentMaxValue += (currentMaxValue + 1);\n                ++minPatch;\n            }\n        }\n        return minPatch;\n    }\n}\n```\n\n---\n\n# Complexity\n- Time complexity: O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n---\n\n# Upvote if it helped \u2B06\uFE0F
['Java']