leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

2452.cpp (669B)


      1 class Solution {
      2   public:
      3     vector<string> twoEditWords(const vector<string> &queries, const vector<string> &dictionary) {
      4         const int n = queries.front().size();
      5 
      6         vector<string> res;
      7         if (n <= 2) return queries;
      8         for (const string &query : queries) {
      9             for (const string &dict : dictionary) {
     10                 int i = 0, j = 0, diff = 0;
     11                 while (i < n) {
     12                     if (query[i++] == dict[j++]) continue;
     13                     if (++diff > 2) goto next;
     14                 }
     15                 res.push_back(query);
     16                 break;
     17             next:;
     18             }
     19         }
     20 
     21         return res;
     22     }
     23 };