LeetCode | 521. Longest Uncommon Subsequence I
题目
Given two strings a and b, return the length of the longest uncommon subsequence between a and b. If the longest uncommon subsequence does not exist, return -1.
An uncommon subsequence between two strings is a string that is a subsequence of one but not the other.
A subsequence of a string s is a string that can be obtained after deleting any number of characters from s.
For example, “abc” is a subsequence of “aebdc” because you can delete the underlined characters in “aebdc” to get “abc”. Other subsequences of “aebdc” include “aebdc”, “aeb”, and “” (empty string).
Example 1:
Input: a = “aba”, b = “cdc”
Output: 3
Explanation: One longest uncommon subsequence is “aba” because “aba” is a subsequence of “aba” but not “cdc”.
Note that “cdc” is also a longest uncommon subsequence.
Example 2:
Input: a = “aaa”, b = “bbb”
Output: 3
Explanation: The longest uncommon subsequences are “aaa” and “bbb”.
Example 3:
Input: a = “aaa”, b = “aaa”
Output: -1
Explanation: Every subsequence of string a is also a subsequence of string b. Similarly, every subsequence of string b is also a subsequence of string a.
Constraints:
1 <= a.length, b.length <= 100
a and b consist of lower-case English letters.
代码
class Solution {public:int findLUSlength(string a, string b) {return a == b ? -1 : max(a.size(), b.size());}
};
一次AC!并且效率超过100.0% C++通过代码~ 不过这次明确了,应该是题目简单!
哈哈哈哈哈哈哈哈 ^ _________________________________ ^
LeetCode | 521. Longest Uncommon Subsequence I相关推荐
- LeetCode 521. Longest Uncommon Subsequence I
题目: Given a group of two strings, you need to find the longest uncommon subsequence of this group of ...
- 521. Longest Uncommon Subsequence I - LeetCode
Question 521. Longest Uncommon Subsequence I Solution 题目大意:给两个字符串,找出非共同子串的最大长度 思路:字符串相等就返回-1,不等就返回长度 ...
- 【leetcode】521. Longest Uncommon Subsequence I
题目如下: 解题思路:本题有点意思.首先如果输入的两个字符串都为空,那么结果是-1:如果两个字符串长度不一样,那么结果是较长的字符串的长度,因为较长的字符串肯定是自身的子序列,但一定不是较短的字符串的 ...
- C#LeetCode刷题之#521-最长特殊序列 Ⅰ(Longest Uncommon Subsequence I)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3949 访问. 给定两个字符串,你需要从这两个字符串中找出最长的特 ...
- [Swift]LeetCode522. 最长特殊序列 II | Longest Uncommon Subsequence II
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★ ➤微信公众号:山青咏芝(shanqingyongzhi) ➤博客园地址:山青咏芝(https://www.cnblog ...
- 【暴力】LeetCode 300. Longest Increasing Subsequence
LeetCode 300. Longest Increasing Subsequence Solution1:我的答案 暴力搜索,时间复杂度O(n2)O(n2)O(n^2) class Solutio ...
- 【动态规划 回文串11】LeetCode 516. Longest Palindromic Subsequence
LeetCode 516. Longest Palindromic Subsequence 本博客转载自:http://www.cnblogs.com/grandyang/p/6493182.html ...
- leetcode 300. Longest Increasing Subsequence | 300. 最长递增子序列(动态规划)
题目 https://leetcode.com/problems/longest-increasing-subsequence/ 题解 难得有官方题解的一道题. 参考:https://leetcode ...
- leetcode (Longest Harmonious Subsequence)
Title:Longest Harmonious Subsequence 594 Difficulty:Easy 原题leetcode地址: https://leetcode.com/probl ...
- LeetCode 594. Longest Harmonious Subsequence
题目: We define a harmonious array is an array where the difference between its maximum value and its ...
最新文章
- 怎么安装python的包_python下如何安装.whl包?
- wxWidgets:构建wxWidgets程序的第一步
- ios html gif 显示,iOS中gif图的显示方法示例
- JavaWeb课程复习资料(十)——修改功能
- python交通标志识别_YOLOv3目标检测实战:交通标志识别
- Maven - 基础入门与安装配置
- segment段,setjmp和longjmp
- 这几天的安排,先做个列表
- WorkerMan 入门学习之(三)基础教程-Timer类的使用
- 剑指offer题目系列一
- LCD 12864B V2.0的使用
- 禾川Q1系列PLC官方教程
- Java解析json数组三种情况
- 数学分析教程(科大)——1.12笔记+习题
- python画满天星_跟我学解Python题-海龟制图满天星
- 植物大战僵尸修改阳光
- 期权定价模型之Heston模型--参数校准与定价【附python代码】
- 什么是CDN什么是高防CDN
- Tian Ji -- The Horse Racing(贪心+STL)
- Apache Solr7.4 入门教程