Skip to content

Commit 2a68bf1

Browse files
authored
Update find-the-maximum-length-of-a-good-subsequence-ii.py
1 parent 4a1135a commit 2a68bf1

File tree

1 file changed

+0
-21
lines changed

1 file changed

+0
-21
lines changed

Python/find-the-maximum-length-of-a-good-subsequence-ii.py

-21
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,3 @@ def maximumLength(self, nums, k):
4343
dp[i][x] = max(dp[i][x], result[i-1] if i-1 >= 0 else 0)+1
4444
result[i] = max(result[i], dp[i][x])
4545
return result[k]
46-
47-
48-
# Time: O(n^2 * k)
49-
# Space: O(n * k)
50-
# dp
51-
class Solution3(object):
52-
def maximumLength(self, nums, k):
53-
"""
54-
:type nums: List[int]
55-
:type k: int
56-
:rtype: int
57-
"""
58-
dp = [[0]*(k+1) for _ in xrange(len(nums))]
59-
result = 0
60-
for i in xrange(len(nums)):
61-
dp[i][0] = 1
62-
for l in xrange(k+1):
63-
for j in xrange(i):
64-
dp[i][l] = max(dp[i][l], dp[j][l]+1 if nums[j] == nums[i] else 1, dp[j][l-1]+1 if l-1 >= 0 else 1)
65-
result = max(result, dp[i][l])
66-
return result

0 commit comments

Comments
 (0)