Java 10 lines (O(n*logn), Space: O(1) , beat 70%)


  • 0
    A
    public int findLongestChain(int[][] pairs) {
        int res = 0;
        Arrays.sort(pairs, (a,b)->a[0]-b[0]);
        int reach = Integer.MIN_VALUE;
        for(int[] pair : pairs){
            if(pair[0]>reach){
                res++;
                reach = pair[1];
            }
            else if(pair[1]<reach) reach = pair[1];            
        }
        return res;
    }

Log in to reply
 

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