[LeetCode] Longest Uncommon Subsequence I 最长非共同子序列之一
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: 3
Explanation: 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.
这道题是在4月1号出的,有人说这是愚人节最好的礼物,哈哈~这道题只是为了后面那道题做铺垫,不过这题确实简单啊,两个字符串的情况很少,如果两个字符串相等,那么一定没有非共同子序列,反之,如果两个字符串不等,那么较长的那个字符串就是最长非共同子序列,参见代码如下:
class Solution {
public:
int findLUSlength(string a, string b) {
return a == b ? - : max(a.size(), b.size());
}
};
[LeetCode] Longest Uncommon Subsequence I 最长非共同子序列之一的更多相关文章
- [LeetCode] Longest Uncommon Subsequence II 最长非共同子序列之二
Given a list of strings, you need to find the longest uncommon subsequence among them. The longest u ...
- LeetCode Longest Uncommon Subsequence II
原题链接在这里:https://leetcode.com/problems/longest-uncommon-subsequence-ii/#/description 题目: Given a list ...
- Leetcode Longest Uncommon Subsequence I
原题链接在这里:https://leetcode.com/problems/longest-uncommon-subsequence-i/#/description 题目: Given a group ...
- LeetCode 594. Longest Harmonious Subsequence (最长的协调子序列)
We define a harmonious array is an array where the difference between its maximum value and its mini ...
- 521 Longest Uncommon Subsequence I 最长特殊序列 Ⅰ
给定两个字符串,你需要从这两个字符串中找出最长的特殊序列.最长特殊序列定义如下:该序列为某字符串独有的最长子序列(即不能是其他字符串的子序列).子序列可以通过删去字符串中的某些字符实现,但不能改变剩余 ...
- 521. Longest Uncommon Subsequence I 最长不同子数组
[抄题]: [暴力解法]: 时间分析: 空间分析: [优化后]: 时间分析: 空间分析: [奇葩输出条件]: [奇葩corner case]: [思维问题]: [一句话思路]: 两个单词的话,就是看谁 ...
- 522 Longest Uncommon Subsequence II 最长特殊序列 II
详见:https://leetcode.com/problems/longest-uncommon-subsequence-ii/description/ C++: 方法一: class Soluti ...
- 【leetcode】521. Longest Uncommon Subsequence I
problem 521. Longest Uncommon Subsequence I 最长非共同子序列之一 题意: 两个字符串的情况很少,如果两个字符串相等,那么一定没有非共同子序列,反之,如果两个 ...
- Leetcode#521. Longest Uncommon Subsequence I(最长特殊序列 Ⅰ)
题目描述 给定两个字符串,你需要从这两个字符串中找出最长的特殊序列.最长特殊序列定义如下:该序列为某字符串独有的最长子序列(即不能是其他字符串的子序列). 子序列可以通过删去字符串中的某些字符实现,但 ...
随机推荐
- swift 相关小随笔
关键词 typealias 对已经存在的类重命名 let 修饰不可变值 var 修饰可变的值 lazy 懒加载修饰符,用到的时候才会加载 convenience 原方法的备用方法,方法一致,但是 ...
- Git中一些远程库操作的细节
最近在公司,老是遇到Git远程操作的问题,现总结如下: 1,本地checkout一个新的分支,向远程push的时候,若远程没有该分支,会新建一个. 2.将远程代码clone到本地修改并commit后, ...
- [COGS 2583]南极科考旅行
2583. 南极科考旅行 ★★ 输入文件:BitonicTour.in 输出文件:BitonicTour.out 简单对比时间限制:1 s 内存限制:256 MB [题目描述] 小美要 ...
- 简单谈谈DNS的工作原理及实践
DNS协议简介 dns(Domain Name System)是一个全球化的分布式数据库系统,用于存储域名和互联网IP地址的映射关系.dns协议是计算机协议栈应用层中,应用最广泛的协议之一.用户每一次 ...
- 敏捷冲刺每日报告——Day5
1.情况简述 Alpha阶段第一次Scrum Meeting 敏捷开发起止时间 2017.10.29 00:00 -- 2017.10.30 00:00 讨论时间地点 2017.10.29晚6:00, ...
- Beta版本敏捷冲刺每日报告——Day2
1.情况简述 Beta阶段第二次Scrum Meeting 敏捷开发起止时间 2017.11.3 08:00 -- 2017.11.3 22:00 讨论时间地点 2017.11.3晚9:00,软工所实 ...
- mahony互补滤波器C编程
//gx...分别为重力加速度在三个轴向的分力 由加速度计测得 //ax...分别为角速度在三个轴向的角速度 由陀螺仪测得 //最后得到最终滤波完毕的x.y.z方向的角度值(°) void IMUup ...
- 用greenlet实现Python中的并发
from greenlet import greenlet def test1(): print 12 gr2.switch() print 34 def test2(): print 56 gr1. ...
- LOW版统计词频
import string path = 'waldnn' with open(path,'r') as text: words = [raw_word.strip(string.punctuatio ...
- Xen Server虚拟机数据恢复的方法和数据恢复过程
在服务器运行过程中如果出现意外情况突然断电很容易引起服务器故障,服务器中的硬件设备损坏可以修复或者购买,但是服务器中的数据一旦发生故障丢失,对于企业来说将是不可估量的损失.那么服务器数据一旦丢失就除了 ...