def findLongestChain(self, pairs): cur, res = float('-inf'), 0 for p in sorted(pairs, key=lambda x: x): if cur < p: cur, res = p, res + 1 return res
My solution followed the same idea after got "time limit exceeded" from my initial DP solution, but yours is obviously much clearer and cleaner. Admire!
lol and found a benefit of using a bit slower language - always force you to find a better solution. If I were using C++ etc maybe the DP solution would pass with no problem and I'll satisfy with that while miss a smarter solution like this!