646. Maximum Length of Pair Chain

二维数组的排序

 Arrays.sort(pairs, (p1, p2) -> (p1[1] - p2[1]));

class Solution {

    public int findLongestChain(int[][] pairs) {
        int re=0,form=Integer.MIN_VALUE;
        Arrays.sort(pairs, (p1, p2) -> (p1[1] - p2[1]));
        for(int i=0;i<pairs.length;i++){
            if(pairs[i][0]>form){
                form=pairs[i][1];
                re++;
            }
        }
        return re;
    }
}

猜你喜欢

转载自blog.csdn.net/m0_37582275/article/details/80039199