作者: 负雪明烛
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. kubernetes 用到的工具及组件

    kubernetes 用到的工具及组件,将所有的组件下载后放到/usr/local/bin目录下(记得chmod a+x /usr/local/bin/*).所有的组件,原则上都用最新的,如果遇到不支 ...

  2. linux 实用指令搜索查找类

    linux 实用指令搜索查找类 目录 linux 实用指令搜索查找类 find指令 locate指令 grep指令和管道符号 | find指令 说明 从指定目录向下递归地遍历其各个子目录,将满足条件的 ...

  3. 学习java 7.19

    学习内容: 接口的组成中加入了默认方法,静态方法,私有方法 接口中默认方法:public default 返回值类型  方法名(参数列表){ } public default void show()  ...

  4. stm32串行设备接口SPI控制max31865

    本人是刚入行的嵌入式,之前也没有多少项目经验,故在公司的这几个月里,可谓是如履薄冰,对于公司不同项目使用的不同的设备之多,数据手册之繁杂,让我不禁望洋兴叹,故而不愿意放弃周末这大好的自我提升时间,努力 ...

  5. Hive(十)【窗口函数】

    目录 一.定义 窗口函数: 标准聚合函数 分析排名函数 二.语法 (1)窗口函数 over([partition by 字段] [order by 字段] [ 窗口语句]) (2)窗口语句 三.需求练 ...

  6. 【c++】解析多文件编程的原理

    其实一直搞不懂为什么头文件和其他cpp文件之间的关系,今晚索性一下整明白 [c++]解析多文件编程的原理 a.cpp #include<stdio.h> int main(){ a(); ...

  7. 【Elasticsearch-Java】Java客户端搭建

    Elasticsearch Java高级客户端   1.  概述 Java REST Client 有两种风格: Java Low Level REST Client :用于Elasticsearch ...

  8. 用oracle中的Row_Number实现分页

    Row_Number实现分页   1:首先是 select ROW_NUMBER() over(order by id asc) as 'rowNumber', * from table1 生成带序号 ...

  9. 【Linux】【Basis】【RHEL】KickStart for RHEL6.8

    1. 概念: 自动安装的脚本,这篇文章以RHEL6.8为例 kickstart for RHEL6.8官方教程:https://access.redhat.com/documentation/en-U ...

  10. js格式化合计金额

    var summoney=1040.010400000000000001; var totalMoney=parseFloat(summoney).toFixed(2); var arry=total ...