Skip to content

Instantly share code, notes, and snippets.

@junddao
Created October 10, 2022 14:23
Show Gist options
  • Save junddao/d3cb3722daf351812e4d752bf8184679 to your computer and use it in GitHub Desktop.
Save junddao/d3cb3722daf351812e4d752bf8184679 to your computer and use it in GitHub Desktop.
leetcode 792
class Solution {
int numMatchingSubseq(String s, List<String> words) {
// List<String> ss = s.split('');
int result = 0;
for(String item in words){
String tempS = s;
List<String> wordsOne = item.split('');
bool isContain = false;
for(String one in wordsOne){
print(wordsOne);
print(one);
if(tempS.contains(one)){
isContain = true;
if(tempS.indexOf(one) == 0) break;
else{
tempS = tempS.substring(0, tempS.indexOf(one) - 1);
}
}
else{
isContain = false;
break;
}
}
print(isContain);
if(isContain == true){
result = result + 1;
}
}
return result;
}
}
void main(){
String s = "abcde";
List<String> words = ["a","bb","acd","ace"];
Solution solution = Solution();
int result = solution.numMatchingSubseq(s, words);
print(result);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment