作者: 负雪明烛
id: fuxuemingzhu
个人博客: http://fuxuemingzhu.cn/


题目地址:https://leetcode.com/problems/longest-uncommon-subsequence-i/description/

题目描述

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.

题目大意

题意很重要啊!这个题目有点长,看了几遍没看太懂,所以一直没做。

给定一组两个的字符串,您需要找到这组两个字符串中最长的不常见的子序列。 最长的不常见的子序列被定义为这些字符串之一的最长子序列,并且该子序列不应该是其他字符串的任何子序列。
子序列是可以通过删除一些字符而不改变剩余元素的顺序从一个序列导出的序列。 简而言之,任何字符串本身都是一个子序列,空字符串是任何字符串的子序列。
输入将是两个字符串,输出需要是最长的不常见子序列的长度。 如果最长不常见的子序列不存在,则返回-1。

解题方法

题意简而言之就是求两个字符串的最长不常见子序列的长度。如果两个字符串相等,那么不存在!如果不等,长度最长的那个字符串就是最长不常见子序列。

脑筋急转弯的题目!怪不得大家对这个题踩了那么多。

class Solution(object):
def findLUSlength(self, a, b):
"""
:type a: str
:type b: str
:rtype: int
"""
return max(len(a), len(b)) if a != b else -1

日期

2018 年 2 月 28 日
2018 年 11 月 9 日 —— 睡眠可以

【LeetCode】521. Longest Uncommon Subsequence I 解题报告(Python)的更多相关文章

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

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

  2. 【LeetCode】522. Longest Uncommon Subsequence II 解题报告(Python)

    [LeetCode]522. Longest Uncommon Subsequence II 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemin ...

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

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

  4. 【leetcode】521. Longest Uncommon Subsequence I

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

  5. 521. Longest Uncommon Subsequence I - LeetCode

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

  6. 521. Longest Uncommon Subsequence I【easy】

    521. Longest Uncommon Subsequence I[easy] Given a group of two strings, you need to find the longest ...

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

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

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

  9. 521 Longest Uncommon Subsequence I 最长特殊序列 Ⅰ

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

随机推荐

  1. perl 数组快速去除重复元素

    这里记录两种perl数组去重的办法,一种利用哈希(hash),一种直接利用perl自带的模块List::MoreUtils内部的函数uniq. 一.利用hash去重 示例代码如下: 1 #!/usr/ ...

  2. linux 线程函数小结

    由于主线程已经开始跑了,次线程还在使用串口打印需要一点时间,因此打印的都是重复的. #include "pthread.h" #include "stdio.h" ...

  3. Oracle-SQL语句的语法顺序和执行顺序

    SQL语句的语法顺序和执行顺序了,我们常见的SQL语法顺序如下: SELECT DISTINCT <Top Num> <select list>FROM [left_table ...

  4. ARM汇编基础指令

    Cortex-A7 常用汇编指令 一.处理器内部数据传输指令 1.mov 将数据从一个寄存器拷贝到另外一个寄存器,或者将一个立即数传递到寄存器里面 MOV R0,R1 @将寄存器 R1 中的数据传递给 ...

  5. 使用dumi生成react组件库文档并发布到github pages

    周末两天玩了下号称西湖区东半球最牛逼的react文档站点生成工具dumi,顺带结合github pages生成了react-uni-comps文档站, 一套弄下来,感觉真香,现在还只是浅尝,高级的特性 ...

  6. Factorization

    Factorization or factoring consists of writing a number or another mathematical object as a product ...

  7. nodejs-npm模块管理器

    JavaScript 标准参考教程(alpha) 草稿二:Node.js npm模块管理器 GitHub TOP npm模块管理器 来自<JavaScript 标准参考教程(alpha)> ...

  8. Linux基础命令---mailq显示邮件队列

    mailq mailq指令可以显示出待发送的邮件队列. 此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.Fedora.   1.语法       mailq   2.选项参数列表 ...

  9. Spring Batch : 在不同steps间传递数据

    参考文档: How can we share data between the different steps of a Job in Spring Batch? Job Scoped Beans i ...

  10. spring中JDBCTemplate的简单应用

    package cn.itcast.datasource.jdbctemplate;import cn.itcast.utils.JDBCUtils;import org.springframewor ...