You are viewing a single comment's thread. Return to all comments →
Language C++, full test case
string appendAndDelete(string s, string t, int k) { string s_less_than_t = s.length() < t.length() ? s : t; int idx = -1; for (int i = 0; i < s_less_than_t.length(); i++) { if (s[i] == t[i]) idx++; else break; } int move = (s.length() - idx - 1) + (t.length() - idx - 1); if (move == k) return "Yes"; if (move < k) { for (int i = idx;; i--) { if (i < 0) move = move + 1; else move = move + 2; if (move > k) return "No"; if (move == k) return "Yes"; } } 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 →
Language C++, full test case