522. Longest Uncommon Subsequence II

class Solution(object):
def subseq(self,w1,w2):
cnt=0
for i in w2:
if cnt<len(w1) and i==w1[cnt]:
cnt+=1
return cnt==len(w1)

def findLUSlength(self, strs):
"""
:type strs: List[str]
:rtype: int
"""
strs.sort(key=len,reverse=True)
for i1,w1 in enumerate(strs):
if all(not self.subseq(w1,w2) for i2,w2 in enumerate(strs) if i1<>i2):
return len(w1)
return -1

猜你喜欢

转载自www.cnblogs.com/ffeng0312/p/9649750.html