6 Line Python Soln


  • 2
    P

    Straight forward solution
    '''

    
    class Solution(object):
        def findLongestChain(self, pairs):
            pairs = sorted(pairs, key=lambda x: x[1])
            newli = [pairs[0]]
            for i in range(0, len(pairs)-1):
                if newli[len(newli)-1][1] < pairs[i + 1][0]:
                    newli.append(pairs[i + 1])
            return len(newli)
    

    '''


  • 0
    J

    @Pythagoras_the_3rd
    a good idea.
    it can be more concise if you just store the second element of pairs in dp and use use newli[-1] to replace newli[len(newli) - 1].


Log in to reply
 

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