You are viewing a single comment's thread. Return to all comments →
Java, full test case
public static String appendAndDelete(String s, String t, int k) { if (s.length() + t.length() <= k) return "Yes"; int lengthOfCommonSubstring = 0; for (int i = 0; i < s.length() && i < t.length() ; i++) { if (s.charAt(i) == t.charAt(i)) { lengthOfCommonSubstring++; continue; } break; } int minNecessaryOperations = (s.length() - lengthOfCommonSubstring) + (t.length() - lengthOfCommonSubstring); if (minNecessaryOperations > k) return "No"; if (minNecessaryOperations == k) return "Yes"; int restOperations = k - minNecessaryOperations; if (lengthOfCommonSubstring * 2 >= restOperations) return restOperations % 2 == 0 ? "Yes" : "No"; return "Yes"; }
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 →
Java, full test case