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

Class Solution

DP/NumberofLongestIncreasingSubsequence.py:67–96  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

65"""
66
67class Solution(object):
68
69 def findNumberOfLIS(self, nums):
70 """
71 :type nums: List[int]
72 :rtype: int
73 """
74 if not nums:
75 return 0
76
77 length = [1] * len(nums)
78 count = [1] * len(nums)
79
80 maxLength = 1
81
82 for i in range(len(nums)):
83 for j in range(i):
84 if nums[i] > nums[j]:
85 if length[j] == length[i]:
86 count[i] = count[j]
87
88 if length[j]+1 == length[i]:
89 count[i] += count[j]
90
91 x = max(length[j]+1, length[i])
92
93 length[i] = x
94 maxLength = max(maxLength, x)
95
96 return sum([count[i] for i,j in enumerate(length) if j == maxLength])
97
98
99

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected