Javascript solution


  • 0
    J
    var minPatches = function(nums, n) {
        var covered=1,count=0,i=0;
        //current covered range is [1,covered)
        while(covered<=n){
            if(i>=nums.length||covered<nums[i]){
                count++;
                covered+=covered;
            }else covered+=nums[i++];
        }
        return count;
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.