522. 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.
|
|
Note:
All the given strings’ lengths will not exceed 10.
The length of the given list will be in the range of [2, 50].
题目大意
给定一组字符串,求最长不公共子序列。
子序列可以通过删除一些字符而不改变其余元素顺序的新序列。
空字符串不属于任何字符串的子序列
解题思路
辅助字典,优化数组遍历。
根据字符串长度对数组进行排序,简化遍历。
再次遍历数组,判断当前字符串是否是数组内其他字符串的子字符串。
代码
|
|