Skip to content

Commit 9b95497

Browse files
committed
Add 521_longest_uncommon_subsequence_one
1 parent 05e08b2 commit 9b95497

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# [Longest Uncommon Subsequence I](https://leetcode.com/problems/longest-uncommon-subsequence-i/description/)
2+
3+
Given two strings a and b, return the length of the longest uncommon subsequence between a and b. If the longest
4+
uncommon subsequence does not exist, return -1.
5+
6+
An uncommon subsequence between two strings is a string that is a subsequence of one but not the other.
7+
8+
A subsequence of a string s is a string that can be obtained after deleting any number of characters from s.
9+
10+
- For example, "abc" is a subsequence of "aebdc" because you can delete the underlined characters in "aebdc" to get "abc".
11+
Other subsequences of "aebdc" include "aebdc", "aeb", and "" (empty string).
12+
13+
Example 1:
14+
```
15+
Input: a = "aba", b = "cdc"
16+
Output: 3
17+
Explanation: One longest uncommon subsequence is "aba" because "aba" is a subsequence of "aba" but not "cdc".
18+
Note that "cdc" is also a longest uncommon subsequence.
19+
```
20+
Example 2:
21+
```
22+
Input: a = "aaa", b = "bbb"
23+
Output: 3
24+
Explanation: The longest uncommon subsequences are "aaa" and "bbb".
25+
```
26+
Example 3:
27+
```
28+
Input: a = "aaa", b = "aaa"
29+
Output: -1
30+
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.
31+
```
32+
Solution
33+
```python
34+
class Solution:
35+
def findLUSlength(self, a: str, b: str) -> int:
36+
if a == b:
37+
return -1
38+
return max(len(a), len(b))
39+
40+
```
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
def find_lus_length(a, b):
2+
if a == b:
3+
return -1
4+
return max(len(a), len(b))
5+
6+
7+
print(find_lus_length(a="aba", b="cdc"))

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ To search for a specific problem please use ```STRG + F``` to search for.
148148
|506|[Relative Ranks](https://github.com/m3xw3ll/LeetCode/blob/master/Algorithms/506_relative_ranks.md)|
149149
|509|[Fibonacci Number](https://github.com/m3xw3ll/LeetCode/blob/master/Algorithms/509_fibonacci_number.md)|
150150
|520|[Detect Capital](https://github.com/m3xw3ll/LeetCode/blob/master/Algorithms/520_detect_capital.md)|
151+
|521|[Longest Uncommon Subsequence I](https://github.com/m3xw3ll/LeetCode/blob/master/Algorithms/521_longest_uncommon_subsequence_one.md)|
151152
|541|[Reverse String II](https://github.com/m3xw3ll/LeetCode/blob/master/Algorithms/541_reverse_string_2.md)|
152153
|551|[Student Attendance Record I](https://github.com/m3xw3ll/LeetCode/blob/master/Algorithms/551_student_attendance_1.md)|
153154
|557|[Reverse Words in a String III](https://github.com/m3xw3ll/LeetCode/blob/master/Algorithms/557_reverse_words_in_a_string_3.md)|

0 commit comments

Comments
 (0)