LeetCode 522. 最长特殊序列 II C#
原题链接
中等
作者:
hpstory
,
2022-06-27 00:22:58
,
所有人可见
,
阅读 122
C# 代码
public class Solution {
public int FindLUSlength(string[] strs) {
int result = -1;
for (int i = 0; i < strs.Length; i++){
bool isSub = false;
for (int j = 0; j < strs.Length; j++){
if (i != j && Check(strs[i], strs[j])){
isSub = true;
break;
}
}
if (!isSub) result = Math.Max(result, strs[i].Length);
}
return result;
}
private bool Check(string a, string b){
if (a.Length > b.Length) return false;
int i = 0;
foreach (char ch in b){
if (i < a.Length && ch == a[i]){
i++;
}
}
return i == a.Length;
}
}