# 分割回文串 II

<p>给你一个字符串 <code>s</code>，请你将 <code>s</code> 分割成一些子串，使每个子串都是回文。</p>

<p>返回符合要求的 <strong>最少分割次数</strong> 。</p>

<div class="original__bRMd">
<div>
<p> </p>

<p><strong>示例 1：</strong></p>

<pre>
<strong>输入：</strong>s = "aab"
<strong>输出：</strong>1
<strong>解释：</strong>只需一次分割就可将 <em>s </em>分割成 ["aa","b"] 这样两个回文子串。
</pre>

<p><strong>示例 2：</strong></p>

<pre>
<strong>输入：</strong>s = "a"
<strong>输出：</strong>0
</pre>

<p><strong>示例 3：</strong></p>

<pre>
<strong>输入：</strong>s = "ab"
<strong>输出：</strong>1
</pre>

<p> </p>

<p><strong>提示：</strong></p>

<ul>
	<li><code>1 <= s.length <= 2000</code></li>
	<li><code>s</code> 仅由小写英文字母组成</li>
</ul>
</div>
</div>


## template

```java
class Solution {
	public int minCut(String s) {
		int n = s.length();
		boolean[][] g = new boolean[n][n];
		for (int i = 0; i < n; i++) {
			Arrays.fill(g[i], true);
		}
		for (int i = n - 1; i >= 0; i--) {
			for (int j = i + 1; j < n; j++) {
				g[i][j] = (s.charAt(i) == s.charAt(j) && g[i + 1][j - 1]);
			}
		}
		int[] f = new int[n];
		Arrays.fill(f, Integer.MAX_VALUE);
		for (int i = 0; i < n; i++) {
			if (g[0][i]) {
				f[i] = 0;
			}
			for (int j = 0; j < i; j++) {
				if (g[j + 1][i]) {
					f[i] = Math.min(f[i], f[j] + 1);
				}
			}
		}
		return f[n - 1];
	}
}


```

## 答案

```java

```

## 选项

### A

```java

```

### B

```java

```

### C

```java

```