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]: [思维问题]: [一句话思路]: 两个单词的话,就是看谁 ...
随机推荐
- [Atcoder Regular Contest 064] Tutorial
Link: ARC064 传送门 C: 贪心+对边界的特殊处理 #include <bits/stdc++.h> using namespace std; typedef long lon ...
- HDU 2819 Swap(二分图匹配)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=2819 [题目大意] 给出一个棋盘,由白格子和黑格子组成,可以交换棋盘的行列, 使得其主对角线为黑格 ...
- [Contest20180323]King
跳蚤国王要召开第二届内阁会议,所以把所有跳蚤都召集到了会议室.所有跳蚤在会议室的圆桌前坐成了一个圈,从$1$到$n$标号,每人的面前都有一盏明灯. 就在会议就要开始的时候,国王突然发现,并不是所有的灯 ...
- 6.2(java学习笔记)字节流
一.FileInputStream 文件输入流从文件中获取输入字节.简单的说就是读取文件. 1.构造方法 FileInputStream(File file)//根据指定文件对象创建一个输入流 2.常 ...
- Exercise02_09
import javax.swing.JOptionPane; public class Acceleration { public static void main(String[] args){ ...
- Java矩阵库—jblas、ujmp、jmatio的相互转化
1)首先使用jmatio(v0.2)从.mat文件读取数据到内存中,并将其转化为二维数组的形式. import com.jmatio.io.MatFileReader; import com.jmat ...
- codevs与noi做题改错本目录
从2016.2.13开始: 1. 排序超时的问题---------目录:-测试习题 2. 超高精度乘法超时问题-----------目录:高精度计算 算法:快速傅里叶算法. 压位算法 3. 高精度 ...
- Linux之ps查找进程用kill终止命令
http://www.cnblogs.com/peida/archive/2012/12/20/2825837.html http://blog.csdn.net/andy572633/article ...
- 部署web Service到tomcat
建立项目 打开jdeveloper 12c,然后新建一个java项目,点击java,生成web services. package simple; import javax.jws.WebMethod ...
- Drupal 7.31 SQL Injection Exp
#-*- coding:utf-8 -*- import urllib2,sys import hashlib # Calculate a non-truncated Drupal 7 compa ...