[leetcode] 522. Longest Uncommon Subsequence II

网友投稿 742 2022-08-23

[leetcode] 522. Longest Uncommon subsequence II

[leetcode] 522. Longest Uncommon Subsequence II

Description

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:

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

分析

题目的意思是:找出字符串数组中所有字符串的最长非公共子序列。

如果一个str是其他字符串的公共子集的话,函数就要返回-1;如果不是,那就是非公共子集,我们就找到了一个非公共子序列,我们更新res,来寻找最大的非公共子集。

代码

class Solution {public: int findLUSlength(vector& strs) { int n=strs.size(); int res=-1; int i=0; int j=0; for(int i=0;i

参考文献

​​[LeetCode] Longest Uncommon Subsequence II 最长非共同子序列之二​​

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:汇总Android Manifest 权限描述大全(汇总报表怎么做)
下一篇:[leetcode] 236. Lowest Common Ancestor of a Binary Tree
相关文章

 发表评论

暂时没有评论,来抢沙发吧~