Created with <3 with dartpad.dev.
Created
October 10, 2022 14:23
-
-
Save junddao/d3cb3722daf351812e4d752bf8184679 to your computer and use it in GitHub Desktop.
leetcode 792
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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