尽可能多的连续子字符串,以使S中的每个字母仅出现在一个子字符串中

时间:2019-02-28 18:38:24

标签: string contiguous

给出一个字符串S。该字符串只有小写英文字母。您必须将字符串分成尽可能多的连续子字符串,以使S中的每个字母仅出现在一个子字符串中,这些子字符串的串联产生S。

S = "abcde"
"ab", "cd", "e"
"a", "b", "c", "d", "e" -> Answer

S = "abcae"
"a", "b", "c", "a", "e" -> Wrong
"abc", "a", "e" -> Wrong
"abca", "e" -> Meets constraint (Answer)
"abcae" -> Meets constratint but is not maximal(Not the answer)

S = "abcabe"
"abcab", "e" -> Meets constratint + maximal (Answer)
"abca", "b", "e" -> Wrong because 'b' appears in multiple substrings.

0 个答案:

没有答案