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:

  1. Both strings' lengths will not exceed 100.
  2. 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】的更多相关文章

  1. 【leetcode】521. Longest Uncommon Subsequence I

    problem 521. Longest Uncommon Subsequence I 最长非共同子序列之一 题意: 两个字符串的情况很少,如果两个字符串相等,那么一定没有非共同子序列,反之,如果两个 ...

  2. Leetcode#521. Longest Uncommon Subsequence I(最长特殊序列 Ⅰ)

    题目描述 给定两个字符串,你需要从这两个字符串中找出最长的特殊序列.最长特殊序列定义如下:该序列为某字符串独有的最长子序列(即不能是其他字符串的子序列). 子序列可以通过删去字符串中的某些字符实现,但 ...

  3. 521. Longest Uncommon Subsequence I - LeetCode

    Question 521. Longest Uncommon Subsequence I Solution 题目大意:给两个字符串,找出非共同子串的最大长度 思路:字符串相等就返回-1,不等就返回长度 ...

  4. 【LeetCode】521. Longest Uncommon Subsequence I 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  5. LeetCode: 521 Longest Uncommon Subsequence I(easy)

    题目: anysubsequence of the other strings. A subsequence is a sequence that can be derived from one se ...

  6. LeetCode 521 Longest Uncommon Subsequence I 解题报告

    题目要求 Given a group of two strings, you need to find the longest uncommon subsequence of this group o ...

  7. *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 ...

  8. 521. Longest Uncommon Subsequence I

    static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); class Solution { publ ...

  9. 521. Longest Uncommon Subsequence I 最长不同子数组

    [抄题]: [暴力解法]: 时间分析: 空间分析: [优化后]: 时间分析: 空间分析: [奇葩输出条件]: [奇葩corner case]: [思维问题]: [一句话思路]: 两个单词的话,就是看谁 ...

随机推荐

  1. 洛谷 P2742 [USACO5.1]圈奶牛Fencing the Cows

    题目描述 农夫约翰想要建造一个围栏用来围住他的奶牛,可是他资金匮乏.他建造的围栏必须包括他的奶牛喜欢吃草的所有地点.对于给出的这些地点的坐标,计算最短的能够围住这些点的围栏的长度. 输入输出格式 输入 ...

  2. 【树状数组】【枚举约数】 - Ambitious Experiment

    给定一个序列,支持以下操作: 对区间[l,r]的每个i,将1i,2i,3i,...这些位置的数都加d. 询问某个位置的数的值. 如果把修改看作对区间[l,r]的每个数+d,那么询问x位置上的数时,显然 ...

  3. 【动态规划】bzoj1270 [BeijingWc2008]雷涛的小猫

    暴力dp是n^2*m的……我们计算每棵树在每层的答案的时候,都需要计算出从那棵树转移过来最优. 但是我们发现,对一棵树而言,从上面转移过来都是一样的,所以我们可以在计算每棵树在每层的答案的时候,先预处 ...

  4. STL之priority_queue2

    描述 使用STL中的优先队列,将一个字符串中的各个字符按照ASCII从小到大顺序排列. 部分代码已经给出,请补充完整,提交时请勿包含已经给出的代码. int main() { int n; cin&g ...

  5. 利用位操作进行IP地址的转化

    1)IPv4地址是一个32位的二进制数,通常被分割位4个“8位二进制数”,为了方便,通常使用“点分十进制”的形式表示成(a.b.c.d)的形式,其中,a,b,c,d都是0~255之间的十进制整数,另外 ...

  6. chrome 技巧 记录一些以前不太熟悉的

    chrome已经不知道用了多少年了,但是还是有些技巧不熟悉,记录下有用的和自己不熟悉的 如何查看dom的绑定事件(查看jquery的绑定事件) 新版本的network的类型选项哪去了? 在Source ...

  7. VMware虚拟机中为Linux 添加虚拟硬盘(VirtualBox方法类似)

    修改1:2014-06-24 11:38:21 Linux添加硬盘是在原来安装的硬盘空间不够或者需要使用其他硬盘上的东西时候的解决办法,因为大多数初学者习惯使用虚拟机,这里以在Vmware虚拟机中实现 ...

  8. Centos7.4 建站系统和软件版本搭配

    一.系统和软件版本搭配 版本: 1.1.2 类型: 建站系统 适用于: Centos7.4 64bit 集成软件版本: nginx_versi=1.12.2 PHP=7.1.13 (已提供提供Zend ...

  9. Python 获取图片格式及像素宽高信息

    # coding: utf8 from PIL import Image img = Image.open("img.jpg") print img.sizeprint img.f ...

  10. Python连接MySQL乱码(中文变问号)

    #coding=utf-8 import MySQLdb db = MySQLdb.connect("IP","用户名","密码",&quo ...