We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Append and Delete
Append and Delete
Sort by
recency
|
1419 Discussions
|
Please Login in order to post a comment
Found a peculiar solution I though I would share:
Comment 1
Calculate the length of the substing of s (starting at the beggining of s) which we do not need to change because it is the same as the corresponding substring of t.
Comment 2
If k >= len(t) + len(s) the answer is always yes because we can delete all the letters of s, continue deleting the empty string if k > len(t) + len(s) and then add the elements of t
Comment 3
min_ops = len(t) + len(s) - 2*i calculates the minimum number of operations needed to transform s to t. If min_ops > k the answer is no. If min_ops = k the answer is yes. If min_ops < k, the answer is yes if the remaining operations are an even number. In this case, after transforming s we would use the remaining number of operations to add and delete an item (or vice versa) until we use all of k.
My Java 8 solution:
This is my solution. It's in python. It's probably a bit over complicated but I'll post it anyway
def appendAndDelete(s, t, k):
Simple C++ solution with the concepts involucred.
My JAVA Solution: