【LeetCode】521. Longest Uncommon Subsequence I 解题报告(Python)
作者: 负雪明烛
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:
- Both strings’ lengths will not exceed 100.
- 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)的更多相关文章
- LeetCode 521 Longest Uncommon Subsequence I 解题报告
题目要求 Given a group of two strings, you need to find the longest uncommon subsequence of this group o ...
- 【LeetCode】522. Longest Uncommon Subsequence II 解题报告(Python)
[LeetCode]522. Longest Uncommon Subsequence II 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemin ...
- Leetcode#521. Longest Uncommon Subsequence I(最长特殊序列 Ⅰ)
题目描述 给定两个字符串,你需要从这两个字符串中找出最长的特殊序列.最长特殊序列定义如下:该序列为某字符串独有的最长子序列(即不能是其他字符串的子序列). 子序列可以通过删去字符串中的某些字符实现,但 ...
- 【leetcode】521. Longest Uncommon Subsequence I
problem 521. Longest Uncommon Subsequence I 最长非共同子序列之一 题意: 两个字符串的情况很少,如果两个字符串相等,那么一定没有非共同子序列,反之,如果两个 ...
- 521. Longest Uncommon Subsequence I - LeetCode
Question 521. Longest Uncommon Subsequence I Solution 题目大意:给两个字符串,找出非共同子串的最大长度 思路:字符串相等就返回-1,不等就返回长度 ...
- 521. Longest Uncommon Subsequence I【easy】
521. Longest Uncommon Subsequence I[easy] Given a group of two strings, you need to find the longest ...
- LeetCode: 521 Longest Uncommon Subsequence I(easy)
题目: anysubsequence of the other strings. A subsequence is a sequence that can be derived from one se ...
- *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 ...
- 521 Longest Uncommon Subsequence I 最长特殊序列 Ⅰ
给定两个字符串,你需要从这两个字符串中找出最长的特殊序列.最长特殊序列定义如下:该序列为某字符串独有的最长子序列(即不能是其他字符串的子序列).子序列可以通过删去字符串中的某些字符实现,但不能改变剩余 ...
随机推荐
- 搭建简单的SpringCloud项目三:问题及解决
GitHub:https://github.com/ownzyuan/test-cloud 前篇:搭建简单的SpringCloud项目一:注册中心和公共层 搭建简单的SpringCloud项目二:服务 ...
- 省时省心DTM,广告转化无难题
内容来源:华为开发者大会2021 HMS Core 6 App Services技术论坛,主题演讲<华为分析服务,助您打造数智化运营闭环方案>. 演讲嘉宾:华为消费者云服务 分析产品总监 ...
- Spark基础:(三)Spark 键值对操作
1.pair RDD的简介 Spark为包含键值对类型的RDD提供了一些专有的操作,这些RDD就被称为pair RDD 那么如何创建pair RDD呢? 在不同的语言中有着不同的创建方式 在pytho ...
- [web安全] 利用pearcmd.php从LFI到getshell
有一段时间没写blog了,主要是事多,加上学的有些迷茫,所以内耗比较大.害,沉下心好好学吧. 漏洞利用背景: 允许文件包含,但session等各种文件包含都已经被过滤了.ctf题中可以关注regist ...
- 【J-Link】J-Link不支持(版本太低)
事情起因,我原本可以烧录和仿真的(版本6.3.4),但是后来安装另一个东西,这个东西里面包含旧的J-Link驱动(版本5.1.2) 它把Keil文件夹下的JLinkARM.dll覆盖了,导致出现下面的 ...
- 随录、EJB和JTA
说道JTA(Java Transction Api),即事务的一种. 事务:说白了就是一组原子操作,是为了保证数据的安全性. 它,分为三类:JDBC事务,JTA事务,还有容器事务. JDBC是由Con ...
- Apache架构师的30条设计原则
本文作者叫 Srinath,是一位科学家,软件架构师,也是一名在分布式系统上工作的程序员. 他是 Apache Axis2 项目的联合创始人,也是 Apache Software 基金会的成员. 他是 ...
- 【Linux】【Shell】【Basic】Bash
命令历史:shell进程会在其会话中保存此前用户提交执行过的命令: ------------------------------------------------------------------ ...
- git 使用https方式进行 pull、push代码免密
由于网络原因我用ssh方法拉取代码每次都提示远程服务连接失败,因此我用了https方式去拉去代码. 这种方式拉取代码每次操作都要输入密码,为了解决这个问题做了一下操作: 在命令行输入 git conf ...
- i++ 和 ++i 探究原理
先看一个例子: package com.test; public class AutoIncrement { public static void main(String[] args) { int ...