在处理下面的问题和测试用例时,我的问题是为什么单个字符“b”是回文?
Given a string s, partition s such that every substring of the partition is a palindrome.
Return the minimum cuts needed for a palindrome partitioning of s.
For example, given s = "aab",
Return 1 since the palindrome partitioning ["aa","b"] could be produced using 1 cut.
提前致谢, 林
最佳答案
回文的定义来自维基百科:
A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward.
单个字符串是回文,因为它满足这个条件。
Min cut 是指让所有的子串都是回文,你需要进行的最少的切割次数。
这是最简单的例子:
s="aaaabbbb"
MinCuts 应该是 1
: "aaaa", "bbbb"
但在给定的示例中,您可以进行 3,4,5,6 等
切割。
具有 3 个剪切的示例:"aa"、"aa"、"bb"、"bb"
此外,minCuts = stringLength-1
总会有一个解决方案,因为每个字符都是回文
关于algorithm - 关于回文相关的算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33182595/