# LeetCode Longest Uncommon Subsequence II

LeetCode Longest Uncommon Subsequence II

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 {
private:
// 判断child是否是par的子序列
bool isSubSeq(const string& par, const string& child) {
int i = 0, j = 0, m = par.size(), n = child.size();
while (i < m&&j < n) {
if (par[i] == child[j])++j;
++i;
}
return j == n;
}
public:
int findLUSlength(vector<string>& strs) {
unordered_map<string, int> hash;
for (const auto& s : strs)++hash[s];
sort(strs.begin(), strs.end(), [](const string& s1, const string& s2) {return s1.size() > s2.size(); });
for (int i = 0; i < strs.size(); ++i) {
if (hash[strs[i]] > 1)continue;
bool isSub = false;
for (int j = i - 1; j >= 0; --j) {
if (isSubSeq(strs[j], strs[i])) {
isSub = true;
break;
}
}
if (!isSub)return strs[i].size();
}
return -1;
}
};
```