forked from Sunchit/Coding-Decoded
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLongestUncommonSubsequenceII.java
More file actions
37 lines (34 loc) · 926 Bytes
/
LongestUncommonSubsequenceII.java
File metadata and controls
37 lines (34 loc) · 926 Bytes
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
26
27
28
29
30
31
32
33
34
35
36
37
class Solution {
public int findLUSlength(String[] strs) {
int maxLen = -1;
for(int i = 0; i < strs.length ; i++){
boolean flag = false ;
int currLen = strs[i].length() ;
for(int j = 0 ; j<strs.length; j++)
{
if(i != j && isSubsequence(strs[i], strs[j]))
{
flag = true ;
break ;
}
}
if(!flag)
{
maxLen = Math.max(maxLen , currLen);
}
}
return maxLen ;
}
public boolean isSubsequence(String a, String b) {
if (a.equals(b)) return true;
int i = 0;
int j = 0;
while (i < a.length() && j < b.length()) {
if (a.charAt(i) == b.charAt(j)) {
i++;
}
j++;
}
return i == a.length();
}
}