Skip to content

Instantly share code, notes, and snippets.

@dailybird
Created July 13, 2018 12:29
Show Gist options
  • Save dailybird/f650ca02b424d17a37d159d9c1acb87e to your computer and use it in GitHub Desktop.
Save dailybird/f650ca02b424d17a37d159d9c1acb87e to your computer and use it in GitHub Desktop.
def appendAndDelete(s: String, t: String, k: Int): String = {
val sLength = s.length
val tLength = t.length
val minLength = Math.min(sLength, tLength)
var done = false
var index = 0
while (done == false && index < minLength) {
if (s(index).equals(t(index)) == false) {
done = true
} else {
index += 1
}
}
val stepCount = (sLength - index) + (tLength - index)
println(index)
println(stepCount)
if (k.equals(stepCount) ||
((k - stepCount) > 0 && 0.equals((k - stepCount) % 2)) ||
k >= stepCount + 2 * index)
"Yes" else "No"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment