7-Liner Java O(nlog(n)) Time O(1) Space


  • 0
    A
    public int findLongestChain(int[][] pairs) {
          Arrays.sort(pairs, (a,b)->a[1]-b[1]);
          int end = Integer.MIN_VALUE, count = 0;
          for(int i=0;i<pairs.length;i++){
              if(pairs[i][0]<=end) continue;
              end = pairs[i][1];
              count++;
          }
          return count;
    }

Log in to reply
 

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