You are viewing a single comment's thread. Return to all comments →
Java solution: public static String appendAndDelete(String s, String t, int k) {
int stringSLength = s.length(); int stringTLength = t.length(); int difference = Math.abs(stringSLength - stringTLength); if(t.charAt(0) != s.charAt(0)){ if(stringSLength + stringTLength <= k){ return "Yes"; } else{ return "No"; } } else{ if(difference == 0 && !s.equals(t)){ for(int i = 0; i < stringSLength; i++){ if (s.charAt(stringSLength - 1 - i) != t.charAt(stringTLength - 1 - i)) { difference = i; break; } } } if(difference <= k){ if(difference % 2 != 0 && k % 2 == 0){ return "No"; } return "Yes"; } else{ return "No"; } }
}
Seems like cookies are disabled on this browser, please enable them to open this website
I agree to HackerRank's Terms of Service and Privacy Policy.
Append and Delete
You are viewing a single comment's thread. Return to all comments →
Java solution: public static String appendAndDelete(String s, String t, int k) {
}