Leetcode 646 Solution
This article provides solution to leetcode question 646 (maximum-length-of-pair-chain)
Access this page by simply typing in "lcs 646" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
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)