MCPcopy Create free account
hub / github.com/HuberTRoy/leetCode / lengthOfLIS

Method lengthOfLIS

DP/longesSubsequence.py:36–55  ·  view source on GitHub ↗

:type nums: List[int] :rtype: int

(self, strings)

Source from the content-addressed store, hash-verified

34
35class Solution(object):
36 def lengthOfLIS(self, strings):
37 """
38 :type nums: List[int]
39 :rtype: int
40 """
41 if not strings:
42 return 0
43 long_ss = []
44
45 for i in strings:
46 if not long_ss:
47 long_ss.append(([i], 1))
48 continue
49 maxs = max(long_ss, key=lambda x: x[0][-1] < i and x[1]+1)
50 if maxs[0][-1] >= i:
51 long_ss.append(([i], 1))
52 else:
53 long_ss.append((maxs[0]+[i], maxs[1]+1))
54
55 return max(long_ss, key=lambda x: x[1])[1]

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected