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. Asp.Net MVC part2 View、Controller详解

    View详解Razor视图引擎简介HtmlHelper强类型页面 Razor视图引擎简介强大的@:表示使用C#代码,相当于aspx中的<%%>可以完成输出功能当遇到html标签时会认为C# ...

  2. python列表和分片

    列表的分片 str = " print("打印第0个元素:" ,str[0]) print("负数表示倒数第N个元素,-1表示倒数第一个元素:" ,s ...

  3. linux+iptables搭建网关服务器

    公司购买的一批云服务器只带内网,配置了一个负载均衡器(lb),这批服务器通过lb可以对外提供服务,但是这批服务器不能主动连接外网,例如使用wget下载文件,或者curl访问ttlsa.com站点. 额 ...

  4. Delphi~通过程序窗体句柄获取程序路径

    http://www.cnblogs.com/Jesses/articles/1636323.html 引用PsAPI var  h:HWND;  pid: Cardinal;  pHandle: T ...

  5. Vmware+Virtualbox+Ubuntu+debian+USB转串口+kermit

    当前的环境是:在Win7笔记本主机上安装VirtualBox+Ubuntu12_04,串口使用USB转串口 如果使用的虚拟机是VirtualBox: 如果使用的虚拟机是Vmware: 执行这步后,主机 ...

  6. SQL:将查询结果插入到另一个表的三种情况!

    一:如果要插入目标表不存在: select * into 目标表 from 表 where ... 二:如果要插入目标表已经存在: insert into 目的表 select * from 表 wh ...

  7. solr curl索引 CSV/Json/xml文件

    在windows系统中,用curl命令工具索引文件命令: 启动solr 在solr-6.6.0\bin的同级目录下的文件夹ImportData下要索引的文件. 1.索引 json文件 curl &qu ...

  8. Scala快学笔记(一)

    一,基本概念: 1,Scala是一种基于JVM的面向对象和函数式编程语言 2,基本类型:数值类型 ->:Byte,Short,Int,Long,Float,Double和布尔类型:Boolean ...

  9. JS 取得当前日期时间(文本形式)

    //-------------------------------------- // 取得当前时间,来自网上,作者不详 //------------------------------------- ...

  10. Linux学习笔记 (六)用户管理命令

    一.用户帐号 1.超级用户:具有操作系统中的最高权限,用来管理和维护操作系统.root用户. 2.普通用户:由root用户来创建,在宿主目录中具有完全权限. 3.程序用户:由应用程序添加,维护某个应用 ...