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.

分析:寻找最长子序列,要求不能是其他序列的子集。这里需要弄清楚,若两个字符串不完全相等,则最长的那个字符串一定都满足上述条件。所以结果很简单,只用判断字符串是否相等即可。

JAVA CODE

class Solution {
public int findLUSlength(String a, String b) {
return a.equals(b) ? -1 : Math.max(a.length(),b.length());
}
}

Longest Uncommon Subsequence I的更多相关文章

  1. [LeetCode] Longest Uncommon Subsequence II 最长非共同子序列之二

    Given a list of strings, you need to find the longest uncommon subsequence among them. The longest u ...

  2. [LeetCode] Longest Uncommon Subsequence I 最长非共同子序列之一

    Given a group of two strings, you need to find the longest uncommon subsequence of this group of two ...

  3. [Swift]LeetCode521. 最长特殊序列 Ⅰ | Longest Uncommon Subsequence I

    Given a group of two strings, you need to find the longest uncommon subsequence of this group of two ...

  4. [Swift]LeetCode522. 最长特殊序列 II | Longest Uncommon Subsequence II

    Given a list of strings, you need to find the longest uncommon subsequence among them. The longest u ...

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

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

  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. 522. Longest Uncommon Subsequence II

    Given a list of strings, you need to find the longest uncommon subsequence among them. The longest u ...

  8. Codeforces Round #396 (Div. 2) A. Mahmoud and Longest Uncommon Subsequence 水题

    A. Mahmoud and Longest Uncommon Subsequence 题目连接: http://codeforces.com/contest/766/problem/A Descri ...

  9. 766A Mahmoud and Longest Uncommon Subsequence

    A. Mahmoud and Longest Uncommon Subsequence time limit per test 2 seconds memory limit per test 256 ...

随机推荐

  1. JQ在线引用地址

    1.7.2版本 百度的引用地址: <script  src="http://libs.baidu.com/jquery/1.7.2/jquery.min.js">< ...

  2. 第2阶段——编写uboot之编译测试以及改进(3)

    编译测试: 1.将写好的uboot复制到linux下面 2.make编译,然后将错误的地方修改,生成boot.bin (编译出错的解决方案:http://www.cnblogs.com/lifexy/ ...

  3. poj3249 拓扑排序+DP

    题意:给出一个有向无环图,每个顶点都有一个权值.求一条从入度为0的顶点到出度为0的顶点的一条路径,路径上所有顶点权值和最大. 思路:因为是无环图,则对于每个点经过的路径求其最大权值有,dp[i]=ma ...

  4. 获取windows任务栏高度的方法

    方法一: TRect rt; SystemParametersInfo(SPI_GETWORKAREA, , &rt, ); //任务栏在下面的高度 int y = ::GetSystemMe ...

  5. 【2017集美大学1412软工实践_助教博客】团队作业3——需求改进&系统设计 成绩公示

    第三次团队作业成绩公布 题目 团队作业3: 需求改进&系统设计 团队成绩 成绩公示如下: 缩写 TD BZ GJ CJ SI WBS GS JG DB SS SJ CS DC Total 分值 ...

  6. 集美大学网络1413第十次作业成绩(团队六) -- 展示博客(Alpha版本)

    题目 团队作业6--展示博客(Alpha版本) 团队作业6成绩  团队/分值 简介& 项目地址 项目目标 (典型用户. 功能描述. 预期用户数量) 如何满足 用户需求 已完成目标 团队分工 团 ...

  7. 201521123100 《Java程序设计》第6周学习总结

    1. 本周学习总结 1.1 面向对象学习暂告一段落,请使用思维导图,以封装.继承.多态为核心概念画一张思维导图,对面向对象思想进行一个总结. 注1:关键词与内容不求多,但概念之间的联系要清晰,内容覆盖 ...

  8. 201521123054《JAVA程序设计》第三周学习总结

    本周学习总结 书面作业 代码阅读 public class Test1 { private int i = 1;//这行不能修改 private static int j = 2; public st ...

  9. 201521123109《java程序设计》第一周学习总结

    1.本章学习总结 java是我这学期学习的一门新的编程语言,个人觉得java还是很深奥的,对于一门新的计算机语言,就像打开了一扇新世界的大门,有许多东西需要不断学习不断探索,除了上课认真听讲,平时还要 ...

  10. 《JAVA程序设计》第13周学习总结

    1. 本章学习总结 以你喜欢的方式(思维导图.OneNote或其他)归纳总结多网络相关内容. GET / HTTP/1.0可以返回一个HTML格式的文本页 IP地址可以用来标识网络上的主机 Socke ...