第一题中规中矩
"""
Given two strings, one is a subsequence if all of the elements of the first string
occur in the same order within the second string. They do not have to be contiguous
in the second string, but order must be maintained. For example, given the string
'I like cheese', the words ('I', 'cheese') are one possible subsequence of that
string您好! 本帖隐藏的内容需要积分高于 188 才可浏览 您当前积分为 0。 使用VIP即刻解锁阅读权限或查看其他获取积分的方式 游客,您好! 本帖隐藏的内容需要积分高于 188 才可浏览 您当前积分为 0。 VIP即刻解锁阅读权限 或 查看其他获取积分的方式 best_inv = 1
if best_len == 0:
dp.append((1, 0, x))
else:
dp.append((best_len, best_inv, x))
max_len = 0
for length, _, _ in dp:
max_len = max(max_len, length)
return n - max_len
|