算法笔记: 力扣#521 最长特殊序列 ⅰ

问题描述


解法


Python 实现

1
2
3
4
5
6
7
8
9
10
class :
def findLUSlength(self, a, b):
"""
:type a: str
:type b: str
:rtype: int
"""
if a == b:
return -1
return max(len(a), len(b))

Java 实现

1
2
3
4
5
6
class {
public int findLUSlength(String a, String b) {
if(a.equals(b)){ return -1; }
return a.length() > b.length() ? a.length() : b.length();
}
}

时间复杂度

O(N).

空间复杂度

O(1).

链接


521. Longest Uncommon Subsequence I
521. 最长特殊序列 Ⅰ
(English version) Algorithm Notes: Leetcode#521 Longest Uncommon Subsequence I