題目連結:https://leetcode-cn.com/problems/longest-word-in-dictionary-through-deleting/
思路:對數組每個字元串采用雙指針判斷
class Solution {
public:
string findLongestWord(string s, vector<string>& d) {
int s_len=s.size();
string result="";
for(auto str:d)
{
int len_str=str.size();
if(result.size()>len_str||(result.size()==len_str&&result<=str))continue;
int i=0;
int j=0;
while(i<s_len&&j<len_str)
{
if(s[i]==str[j])
{
j++;
}
i++;
}
if(j==len_str)
result=str;
}
return result;
}
};