521.Longest Uncommon Subsequence I
来源:互联网 发布:上海升级网络 不靠谱 编辑:程序博客网 时间:2024/05/21 18:48
题目:
Given a group of two strings, you need to find the longest uncommon subsequence of this group of two strings. 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 two 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"Output: 3Explanation: The longest uncommon subsequence is "aba" (or "cdc"),
because "aba" is a subsequence of "aba",
but not a subsequence of any other strings in the group of two strings.
Note:
1. Both strings' lengths will not exceed 100.
2. Only letters from a ~ z will appear in input strings.
思路:这个题目很简单,但是容易想复杂,会受找最长相同序列的影响。这个题目就是先看a和b是否相同,若相同则返回-1.若不相同则返回最长的字符串长度。
代码:
class Solution {
public:
int findLUSlength(string a, string b) {
if(a==b)
{
return -1;
}
else
{
return max(a.size(),b.size());
}
}
};
- 521. Longest Uncommon Subsequence I
- 521. Longest Uncommon Subsequence I
- 521. Longest Uncommon Subsequence I
- 521. Longest Uncommon Subsequence I
- 521. Longest Uncommon Subsequence I
- 521.Longest Uncommon Subsequence I
- 521. Longest Uncommon Subsequence I
- 521. Longest Uncommon Subsequence I
- 521. Longest Uncommon Subsequence I
- 521. Longest Uncommon Subsequence I
- 521. Longest Uncommon Subsequence I
- 521. Longest Uncommon Subsequence I
- 521. Longest Uncommon Subsequence I
- 521. Longest Uncommon Subsequence I
- 521. Longest Uncommon Subsequence I
- 521. Longest Uncommon Subsequence I
- Longest Uncommon Subsequence I
- Longest Uncommon Subsequence I
- Linux vsftpd 的安装
- Pots(由于我的zz,被搞死了lol)
- 当HashMap的键遇见自定义类型时
- Django 新手之常见错误--亲身体验,持续更新ing...[哭]
- Java Web Servlet
- 521.Longest Uncommon Subsequence I
- 02Groovy语法(一)
- [Command]Linux 文件格式化处理
- 这题别看了,跳过吧
- 【Web】锋利的jquery知识点总结
- 【BZOJ1040】骑士(ZJOI2008)-环套树+最大权值独立集
- GO语言结构体
- spring cloud实现微服务容错处理
- TNetHTTPClient演示