Share my simple Java code
public class Solution {\n        public int minPatches(int[] nums, int n) {\n            int count = 0, i = 0;\n            for (long covered=0; covered < n; ) 
    public class Solution {\n        public int minPatches(int[] nums, int n) {\n            int count = 0, i = 0;\n            for (long covered=0; covered < n; ) {\n                if ((i<nums.length && nums[i]>covered+1) || i>=nums.length) {  // at this moment, we need (covered+1), patch it.\n                    covered += covered+1;\n                    ++count;\n                } else { covered += nums[i++]; }\n            }\n            return count;\n        }\n    }
[]