dp 最大递增子序列问题。
- 先对 letters 进行排序
- 初始化 dp, dp[0] = 1
- dp[i] = max(dp[j] + 1, dp[i]) j < i and letters[i][0] > letters[j][0] and letters[i][1] > letters[j][1]
#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
#
# @param letters int整型二维数组
# @return int整型
#
class Solution:
def maxLetters(self , letters: List[List[int]]) -> int:
# write code here
letters.sort()
n = len(letters)
dp = [1 for _ in range(n)]
for i in range(1, n):
for j in range(i):
if letters[i][0] > letters[j][0] and letters[i][1] > letters[j][1]:
dp[i] = max(dp[i], dp[j] + 1)
return max(dp)