C++ Concise Solution


  • 0
    I
    class Solution {
    public:
        int findLongestChain(vector<vector<int>>& pairs) {
            sort(pairs.begin(), pairs.end(), [](vector<int> f, vector<int> s){return f[1] < s[1];});
            int res = 1, last = 0;
            for (int i = 0; i < pairs.size(); i++) {
                if (pairs[i][0] > pairs[last][1]) {
                    last = i;
                    res++;
                }
            }
            return res;
        }
    };
    

Log in to reply
 

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