Easiest nlogn time O(1) space solution


  • 0
    G
    public int findLongestChain(int[][] pairs) {
            
            Arrays.sort(pairs, (a1, a2) -> a1[1] - a2[1]);
            int count = 1;
            int end = pairs[0][1];
            for(int i=1;i<pairs.length;i++){
                if(pairs[i][0] > end){
                    count++;
                    end = pairs[i][1];
                }
            }
            return count;
        }
    

Log in to reply
 

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