java nlogn solution


  • 0
    H
        public int findLongestChain(int[][] pairs) {
            // sort
            Arrays.sort(pairs, (a, b) -> (a[1]-b[1]));
            int max = 1;
            int index = 0;
            for(int i = 1;i<pairs.length;i++){
                if(pairs[index][1]<pairs[i][0]){
                    max++;
                    index = i;
                }
            }
            return max;
        }
    

Log in to reply
 

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