File tree 2 files changed +38
-0
lines changed
solution/0521.Longest Uncommon Subsequence I
2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ ## 最长特殊序列 Ⅰ
2
+
3
+ ### 问题描述
4
+
5
+ 给定两个字符串,你需要从这两个字符串中找出最长的特殊序列。最长特殊序列定义如下:该序列为某字符串独有的最长子序列(即不能是其他字符串的子序列)。
6
+
7
+ 子序列可以通过删去字符串中的某些字符实现,但不能改变剩余字符的相对顺序。空序列为所有字符串的子序列,任何字符串为其自身的子序列。
8
+
9
+ 输入为两个字符串,输出最长特殊序列的长度。如果不存在,则返回 ` -1 ` 。
10
+
11
+ ** 示例:**
12
+ ```
13
+ 输入: "aba", "cdc"
14
+ 输出: 3
15
+ 解析: 最长特殊序列可为 "aba" (或 "cdc")
16
+ ```
17
+
18
+ ** 提示:**
19
+ - 两个字符串长度均小于100。
20
+ - 字符串中的字符仅含有 'a'~ 'z'。
21
+
22
+ ### 解法
23
+
24
+ 若` a ` 与` b ` 相等,则不存在最长子序列;若不相等,则其中较长的就是就是最长子序列。
25
+
26
+ ``` python
27
+ class Solution :
28
+ def findLUSlength (self , a , b ):
29
+ return - 1 if a == b else max (len (a), len (b))
30
+ ```
Original file line number Diff line number Diff line change
1
+ class Solution :
2
+ def findLUSlength (self , a , b ):
3
+ """
4
+ :type a: str
5
+ :type b: str
6
+ :rtype: int
7
+ """
8
+ return - 1 if a == b else max (len (a ), len (b ))
You can’t perform that action at this time.
0 commit comments