# # 【LeetCode】522. Longest Uncommon Subsequence II 解题报告（Python）

## # 题目描述：

Given a list of strings, you need to find the longest uncommon subsequence among them. The longest uncommon subsequence is defined as the longest subsequence of one of these strings and this subsequence should not be any subsequence of the other strings.

A subsequence is a sequence that can be derived from one sequence by deleting some characters without changing the order of the remaining elements. Trivially, any string is a subsequence of itself and an empty string is a subsequence of any string.

The input will be a list of strings, and the output needs to be the length of the longest uncommon subsequence. If the longest uncommon subsequence doesn't exist, return -1.

Example 1:

``````Input: "aba", "cdc", "eae"
Output: 3
``````

Note:

1. All the given strings' lengths will not exceed 10.
2. The length of the given list will be in the range of [2, 50].

## # 解题方法

``````class Solution(object):
def findLUSlength(self, strs):
"""
:type strs: List[str]
:rtype: int
"""
longest = -1
_len = len(strs)
for i in range(_len):
issub = False
for j in range(_len):
if i == j:
continue
if self.checkSubString(strs[i], strs[j]):
issub = True
break
if not issub:
longest = max(longest, len(strs[i]))
return longest

def checkSubString(self, substr, string):
if len(substr) > len(string): return False
if substr == string: return True
if not substr: return True
pos = 0
for i in range(len(string)):
if pos == len(substr):
break
if substr[pos] == string[i]:
pos += 1
return pos == len(substr)
``````

1. http://www.cnblogs.com/grandyang/p/6680548.html
2. https://blog.csdn.net/zsensei/article/details/75227927

## # 日期

2018 年 8 月 27 日 ———— 就要开学了！