Simple Easy to Understand Java Solution || Faster than 100%
Logic\n\nIterating the nums[], and keeps adding them up, and we are getting a running sum. At any position, if nums[i] > sum+1, them we are sure we have to patc
**Logic**\n```\nIterating the nums[], and keeps adding them up, and we are getting a running sum. At any position, if nums[i] > sum+1, them we are sure we have to patch \na sum+1 because all nums before index i can\'t make sum+1 even add all of them up, and all nums after index i are all simply too large.\n```\n\n**Solution**\n```\nclass Solution {\n     public int minPatches(int[] nums, int n) {\n        long sum = 0;\n        int count = 0;\n        for (int x : nums) {\n            if (sum >= n) break;\n            while (sum+1 < x && sum < n) { \n                ++count;\n                sum += sum+1;\n            }\n            sum += x;\n        }\n        while (sum < n) {\n            sum += sum+1;\n            ++count;\n        }\n        return count;\n    }\n}\n```
['Java']