Leetcode 646 Solution

This article provides solution to leetcode question 646 (maximum-length-of-pair-chain)

https://leetcode.com/problems/maximum-length-of-pair-chain

Solution

class Solution: def findLongestChain(self, pairs: List[List[int]]) -> int: s = []
for pair in sorted(pairs): if not s or s[-1][1] < pair[0]: s.append(pair) elif s[-1][1] > pair[1]: s[-1] = pair
return len(s)