521. Longest Uncommon Subsequence I【easy】
521. Longest Uncommon Subsequence I【easy】
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.
解法一:
class Solution {
public:
int findLUSlength(string a, string b) {
if (a.size() != b.size()) {
return max(a.size(), b.size());
}
else {
return (a == b ? - : a.size());
}
}
};
521. Longest Uncommon Subsequence I【easy】的更多相关文章
- 【leetcode】521. Longest Uncommon Subsequence I
problem 521. Longest Uncommon Subsequence I 最长非共同子序列之一 题意: 两个字符串的情况很少,如果两个字符串相等,那么一定没有非共同子序列,反之,如果两个 ...
- Leetcode#521. Longest Uncommon Subsequence I(最长特殊序列 Ⅰ)
题目描述 给定两个字符串,你需要从这两个字符串中找出最长的特殊序列.最长特殊序列定义如下:该序列为某字符串独有的最长子序列(即不能是其他字符串的子序列). 子序列可以通过删去字符串中的某些字符实现,但 ...
- 521. Longest Uncommon Subsequence I - LeetCode
Question 521. Longest Uncommon Subsequence I Solution 题目大意:给两个字符串,找出非共同子串的最大长度 思路:字符串相等就返回-1,不等就返回长度 ...
- 【LeetCode】521. Longest Uncommon Subsequence I 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- LeetCode: 521 Longest Uncommon Subsequence I(easy)
题目: anysubsequence of the other strings. A subsequence is a sequence that can be derived from one se ...
- LeetCode 521 Longest Uncommon Subsequence I 解题报告
题目要求 Given a group of two strings, you need to find the longest uncommon subsequence of this group o ...
- *521. Longest Uncommon Subsequence I (bit manipulation 2^n)
Given a group of two strings, you need to find the longest uncommon subsequence of this group of two ...
- 521. Longest Uncommon Subsequence I
static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); class Solution { publ ...
- 521. Longest Uncommon Subsequence I 最长不同子数组
[抄题]: [暴力解法]: 时间分析: 空间分析: [优化后]: 时间分析: 空间分析: [奇葩输出条件]: [奇葩corner case]: [思维问题]: [一句话思路]: 两个单词的话,就是看谁 ...
随机推荐
- CodeForces - 283E Cow Tennis Tournament
Discription Farmer John is hosting a tennis tournament with his n cows. Each cow has a skill level s ...
- 【kmp算法】poj2406 Power Strings
如果next[n]<n/2,一定无解. 否则,必须要满足n mod (n-next[n]) = 0 才行,此时,由于next数组的性质,0~n-next[n]-1的部分一定是最小循环节. [ab ...
- 小白的Python之路 day5 os,sys模块详解
os模块详解 1.作用: 提供对操作系统调用的接口 2.常用方法: os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径os.chdir("dirname" ...
- 上传--下载HDFS文件并指定文件物理块的大小
使用hdfs的api接口分别实现从本地上传文件到集群和从集群下载文件到本地. 1)上传文件主要是使用FileSystem类的copyFromLocalFile()方法来实现,另外我们上传文件时可以指定 ...
- catalina_home与catalina_base
CATALINA_HOME是Tomcat的安装目 录,CATALINA_BASE是Tomcat的工作目录. 如果我们想要运行Tomcat的多个实例,但是不想安装多个Tomcat软件副本.那么我们可以配 ...
- Android开发工具
Android开发工具: AndroidDevTools: 收集整理Android开发所需的Android SDK.开发中用到的工具.Android开发教程.Android设计规范,免费的设计素材等. ...
- winform 窗体实现增删改查(CRUD)窗体基类模式
参考博客下方:http://www.cnblogs.com/wuhuacong/archive/2010/05/31/1748579.html 对于一般常用到的编辑数据.新增数据窗体,分开了两个不同的 ...
- display:flex;多行多列布局学习
从以前的table布局到现在的div布局,再到未来的flex布局,CSS重构方面对展示行和适应性的要求越来越高: 首先来比较一下布局方式的更新意义: table布局: 优点:1.兼容性好,ie6.ie ...
- Web服务器在外网能裸奔多久?
很多时候我们轻易地把Web服务器暴露在公网上,查看一下访问日志,可以看到会收到大量的攻击请求,这个是网站开通后几个小时收到的请求: 1. 探测服务器信息 在上线一分钟,收到OPTION请求探测. ...
- uCOS-ii笔记
ucos ii system 文件结构 上层: 应用软件,用户代码 中层: 与处理器无关代码 与应用程序相关配置文件 与处理器有关代码 下层: 硬件(cpu,interupt,timer,gpio,i ...