题目

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相关推荐

  1. LeetCode 521. Longest Uncommon Subsequence I

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

  2. 521. Longest Uncommon Subsequence I - LeetCode

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

  3. 【leetcode】521. Longest Uncommon Subsequence I

    题目如下: 解题思路:本题有点意思.首先如果输入的两个字符串都为空,那么结果是-1:如果两个字符串长度不一样,那么结果是较长的字符串的长度,因为较长的字符串肯定是自身的子序列,但一定不是较短的字符串的 ...

  4. C#LeetCode刷题之#521-最长特殊序列 Ⅰ​​​​​​​(Longest Uncommon Subsequence I)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3949 访问. 给定两个字符串,你需要从这两个字符串中找出最长的特 ...

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

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★ ➤微信公众号:山青咏芝(shanqingyongzhi) ➤博客园地址:山青咏芝(https://www.cnblog ...

  6. 【暴力】LeetCode 300. Longest Increasing Subsequence

    LeetCode 300. Longest Increasing Subsequence Solution1:我的答案 暴力搜索,时间复杂度O(n2)O(n2)O(n^2) class Solutio ...

  7. 【动态规划 回文串11】LeetCode 516. Longest Palindromic Subsequence

    LeetCode 516. Longest Palindromic Subsequence 本博客转载自:http://www.cnblogs.com/grandyang/p/6493182.html ...

  8. leetcode 300. Longest Increasing Subsequence | 300. 最长递增子序列(动态规划)

    题目 https://leetcode.com/problems/longest-increasing-subsequence/ 题解 难得有官方题解的一道题. 参考:https://leetcode ...

  9. leetcode (Longest Harmonious Subsequence)

    Title:Longest Harmonious Subsequence    594 Difficulty:Easy 原题leetcode地址: https://leetcode.com/probl ...

  10. LeetCode 594. Longest Harmonious Subsequence

    题目: We define a harmonious array is an array where the difference between its maximum value and its ...

最新文章

  1. 怎么安装python的包_python下如何安装.whl包?
  2. wxWidgets:构建wxWidgets程序的第一步
  3. ios html gif 显示,iOS中gif图的显示方法示例
  4. JavaWeb课程复习资料(十)——修改功能
  5. python交通标志识别_YOLOv3目标检测实战:交通标志识别
  6. Maven - 基础入门与安装配置
  7. segment段,setjmp和longjmp
  8. 这几天的安排,先做个列表
  9. WorkerMan 入门学习之(三)基础教程-Timer类的使用
  10. 剑指offer题目系列一
  11. LCD 12864B V2.0的使用
  12. 禾川Q1系列PLC官方教程
  13. Java解析json数组三种情况
  14. 数学分析教程(科大)——1.12笔记+习题
  15. python画满天星_跟我学解Python题-海龟制图满天星
  16. 植物大战僵尸修改阳光
  17. 期权定价模型之Heston模型--参数校准与定价【附python代码】
  18. 什么是CDN什么是高防CDN
  19. Tian Ji -- The Horse Racing(贪心+STL)
  20. Apache Solr7.4 入门教程

热门文章

  1. RationalDMIS基于CAD的编程测量
  2. html中伪类选择符,【CSS选择符】伪类和伪元素
  3. 元宇宙:不透明面纱下的“康德主义”
  4. 坚持学习100天:象棋网上对弈系统(表示看不懂,有待加油)
  5. python,画3D图,瀑布图
  6. 隐私泄露距离你我有多远?APP扩大个人隐私收集,增大隐私保护难度
  7. 转载:F28335 Ecap使用总结
  8. java后端必会【基础知识点】
  9. 11张好用的项目管理全流程图,支持下载保存(PMP项目管理可用)
  10. 程序员的有个坏习惯!