521. Longest Uncommon Subsequence I
来源:互联网 发布:c语言如何输入n个整数 编辑:程序博客网 时间:2024/05/16 17:28
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:
- Both strings' lengths will not exceed 100.
- Only letters from a ~ z will appear in input strings.
题目链接:https://leetcode.com/problems/longest-uncommon-subsequence-i/#/description
题目大意:两个字符串中最长的字符串是否为另一字符串的子字符串,如果是,则返回-1,否则返回最长字符串长度。
思路:比较两个字符串的长度,若不相等,则返回长度的较大值,若相等则再判断两个字符串是否相同,若相同则返回-1,否则返回长度。
参考代码:
class Solution {public: int findLUSlength(string a, string b) { int n = a.size() , m = b.size() ; if ( n != m ) return max ( n , m ) ; if ( a == b ) return -1 ; return n ; }};
- 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
- 浏览器拦截跨域请求处理方法(同源策略不允许读取服务器远程资源)
- [数据库学习SQLSERVER] 学习笔记
- 八、分组函数/聚合函数/双行处理函数
- 关于zxing扫码界面的优化
- 148. Sort List
- 521. Longest Uncommon Subsequence I
- 利用Python解析Excel文件
- 如何在个人博客中插入Jsbin或者jsfiddle代码
- 快速排序
- ubuntu下解决端口被占用问题
- Android 性能:避免在Android上使用ENUM
- git 指令
- 计数排序
- Mysql索引注意事项