You are viewing a single comment's thread. Return to all comments →
Thing is, you need to use exactly k moves, no more, no less. Else, fail.
string appendAndDelete(string s, string t, int k) { int n = s.size(); int m = t.size(); int i = 0; while (i < n && i < m && s[i] == t[i]) { i++; } int opsNeeded = (n - i) + (m - i); if (opsNeeded > k) { return "No"; } else if ((k - opsNeeded) % 2 == 0 || k >= n + m) { return "Yes"; } else { return "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 →
Thing is, you need to use exactly k moves, no more, no less. Else, fail.