524. 通过删除字母匹配到字典里最长单词
判断 \(b\) 是否是 \(a\) 的子序列
class Solution {
public:
bool isP(string& a, string& b){
int n = a.size(), m = b.size(), i = 0, j = 0;
while(i < n && j < m)if(a[i ++] == b[j]) ++j;
return j == m;
}
string findLongestWord(string s, vector<string>& dictionary) {
string res = "";
for(auto& e : dictionary)
if(isP(s, e) && (e.size() > res.size() || e.size() == res.size() && e < res)) res = e;
return res;
}
};