2746. Decremental String Concatenation
You are given a 0-indexed array
wordscontainingnstrings.Let’s define a join operation
join(x, y)between two stringsxandyas concatenating them intoxy. However, if the last character ofxis equal to the first character ofy, one of them is deleted.For example
join("ab", "ba") = "aba"andjoin("ab", "cde") = "abcde".You are to perform
n - 1join operations. Letstr0 = words[0]. Starting fromi = 1up toi = n - 1, for theithoperation, you can do one of the following:
- Make
stri = join(stri - 1, words[i])- Make
stri = join(words[i], stri - 1)Your task is to minimize the length of
strn - 1.Return an integer denoting the minimum possible length of
strn - 1.
1 | class Solution { |