关于回文相关的算法

about algorithm related to palindrome

正在解决下面的问题,并使用测试用例,我的问题是为什么单个字符 '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 etc 削减。 有 3 个切口的示例:"aa", "aa", "bb", "bb"

也总是会有 minCuts = stringLength-1 的解决方案,因为每个字符都是回文