You are viewing a single comment's thread. Return to all comments →
C++ solution
string appendAndDelete(string s, string t, int k) { int sl = s.length(); int tl = t.length(); if(k > (sl + tl)) return "Yes"; int length = 0; int diffLength = 0; if(sl >= tl) { length = tl; diffLength = sl - tl; } else { length = sl; diffLength = tl - sl; } if(diffLength > k) return "No"; int diffIndex = length; for(int i = 0; i < length; i++) { if(s[i] != t[i]) { diffIndex = i; break; } } int operations = (sl + tl - 2*diffIndex); if(operations == k || (operations % 2 == k % 2 && operations < 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 →
C++ solution