- 假定s串是长串,t是短串,则交换一下s,t串,方便后续操作
- 如果t是s的子串,那么t的子序列一定能在s里找到,一定没有特殊子序列的存在,所以返回-1
- 如果t不是s的子串,那么s串在t里一定找不到,s的子序列不可能比s串的长度大,所以返回s串的长度即可
- 代码如下:
class Solution:
def longestUniqueSubsequence(self , s: str, t: str) -> int:
# write code here
if len(s) < len(t):
s, t = t, s
if s.find(t) >= 0:
return -1
else:
return len(s)