Easy JavaScript solution (Finding minimum number of sub-ranges)


  • 0
    Z

    The second return is to debug while running test input,O(n)time, O(1)space

    /**
     * @param {number[][]} points
     * @return {number}
     */
    var findMinArrowShots = function(points) {
        let rtn = 0;
        points.sort(function(a,b){return a[0] - b[0];});
        for(let i = 0; i< points.length; i++, rtn++){
            while(i < points.length - 1 && points[i][1] >= points[i+1][0]){
                points[i+1] = [Math.max(points[i][0],points[i+1][0]), Math.min(points[i][1],points[i+1][1])];
                i++;
            }
        }
        return rtn;
        return [points,rtn];
    };
    
    

Log in to reply
 

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