You are viewing a single comment's thread. Return to all comments →
C++ O(n) solution:
string appendAndDelete(string s, string t, int k) { if (k > s.size() + t.size()) return "Yes"; int necessary_moves {0}; string::iterator s_it {s.begin()}, t_it {t.begin()}; while (s_it != s.end() && t_it != t.end() && *s_it == *t_it){ s_it++; t_it++; } necessary_moves += s.end() - s_it; // Necessary deletions necessary_moves += t.end() - t_it; // Necessary additions return necessary_moves <= k && (k == necessary_moves || (k-necessary_moves) %2 == 0) ? "Yes" : "No"; }
Seems like cookies are disabled on this browser, please enable them to open this website
Append and Delete
You are viewing a single comment's thread. Return to all comments →
C++ O(n) solution: