LeetCode 最长特殊序列 II
class Solution {
public int findLUSlength(String[] strs) {
int ret = -1;
if (strs == null || strs.length == 0) {
return ret;
}
int len = strs.length;
for (int i = 0; i < len; i++) {
boolean isSubsequence = false;
for (int j = 0; j < len; j++) {
if (i != j && isSubsequence(strs[i], strs[j])) {
isSubsequence = true;
break;
}
}
if (!isSubsequence) {
ret = Math.max(ret, strs[i].length());
}
}
return ret; }
public boolean isSubsequence(String x, String y) { int j = 0; for (int i = 0; i < y.length() && j < x.length(); i++) if (x.charAt(j) == y.charAt(i)) j++; return j == x.length(); }
}
return ret; }
public boolean isSubsequence(String x, String y) { int j = 0; for (int i = 0; i < y.length() && j < x.length(); i++) if (x.charAt(j) == y.charAt(i)) j++; return j == x.length(); }
}