FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
leetcode/java/521_Longest_Uncommon_Subsequence_I.java at master · jakehoare/leetcode · GitHub
jakehoare
/
leetcode
Public
Notifications
You must be signed in to change notification settings
Fork
30
Star
51
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
leetcode
/
java
/
521_Longest_Uncommon_Subsequence_I.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
25 lines (22 loc) · 1.07 KB
Breadcrumbs
leetcode
/
java
/
521_Longest_Uncommon_Subsequence_I.java
Copy path
File metadata and controls
25 lines (22 loc) · 1.07 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/*
https://leetcode.com/problems/longest-uncommon-subsequence-i/
Given a group of two strings, you need to find the longest uncommon subsequence of this group of two strings. The
longest uncommon subsequence is defined as the longest subsequence of one of these strings and this subsequence should
not be any subsequence of the other strings.
A subsequence is a sequence that can be derived from one sequence by deleting some characters without changing the
order of the remaining elements. Trivially, any string is a subsequence of itself and an empty string is a subsequence
of any string.
The input will be two strings, and the output needs to be the length of the longest uncommon subsequence. If the
longest uncommon subsequence doesn't exist, return -1.
If strings are not same then the longer can creaet a subsequence that is not common to shorter.
Else there is no subsequnce.
Time - O(min(m, n))
Space - O(1)
*/
class
Solution
{
public
int
findLUSlength
(
String
a
,
String
b
) {
if
(
a
.
equals
(
b
))
return
-
1
;
return
Math
.
max
(
a
.
length
(),
b
.
length
());
}
}
Back
|
FazBrowse Home
|
New Git URL