leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
2452.cpp (669B)
0 class Solution {
1 public:
2 vector<string> twoEditWords(const vector<string> &queries, const vector<string> &dictionary) {
3 const int n = queries.front().size();
5 vector<string> res;
6 if (n <= 2) return queries;
7 for (const string &query : queries) {
8 for (const string &dict : dictionary) {
9 int i = 0, j = 0, diff = 0;
10 while (i < n) {
11 if (query[i++] == dict[j++]) continue;
12 if (++diff > 2) goto next;
13 }
14 res.push_back(query);
15 break;
16 next:;
17 }
18 }
20 return res;
21 }
22 };