algorithm notes: leetcode#521 longest uncommon subsequence i

Problem


Solution


Python implementation

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 implementation

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();
}
}

Time complexity

O(N).

Space complexity

O(1).


521. Longest Uncommon Subsequence I
(中文版) 算法笔记: 力扣#521 最长特殊序列 Ⅰ