Greedy Java O(nlogn)) Solution - 91ms


  • 0
    public class Solution {
        public int findLongestChain(int[][] pairs) {
            Arrays.sort(pairs, (a,b)->a[1]-b[1]);
            
            int n=1, start=pairs[0][1];
            for(int i=1;i<pairs.length;i++){
            	if(start<pairs[i][0]){
            		n++;
            		start=pairs[i][1];
            	}
            }
            
            return n;
        }
    }
    

Log in to reply
 

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