147_leetcode_Palindrome Partitioning II
来源:互联网 发布:怀孕食谱软件 编辑:程序博客网 时间:2024/05/17 23:09
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.
1:注意特殊情况;2:从前到后遍历字符串,在遍历的过程中检测从i到j之间的字符子串是不是回文,如果是回文,设置回文标识,并计算相应的最小分割。
int minCut(string s) { if(s.length() <= 1) { return 0; } int size = (int)s.length(); vector<int> minResult(size + 1, 0); for(int i = 0; i <= size; i++) { minResult[i] = i - 1; } vector<vector<bool> > flagResult(size, vector<bool>(size, false)); for(int i = 0; i < size; i++) { for(int j = 0; j <= i; j++) { if(s[i] == s[j] && (i - j <= 2 || flagResult[j+1][i-1] == true)) { flagResult[j][i] = true; minResult[i+1] = (minResult[i+1] > minResult[j] + 1 ? minResult[j] + 1 : minResult[i+1]); } } } return minResult[size]; }
0 0
- 147_leetcode_Palindrome Partitioning II
- 118_leetcode_Palindrome Partitioning
- LeetCode : Palindrome Partitioning II
- [leetcode] Palindrome Partitioning II
- leetcode:Palindrome Partitioning II
- Palindrome Partitioning II
- 【leetcode】Palindrome Partitioning II
- Palindrome Partitioning II
- leetcode - Palindrome Partitioning II
- Palindrome Partitioning II
- Palindrome Partitioning II
- [LeetCode]Palindrome Partitioning II
- [Leetcode]Palindrome Partitioning II
- [leetcode]Palindrome Partitioning II
- Palindrome Partitioning II
- leetcode Palindrome Partitioning II
- Palindrome Partitioning II
- LetCode:Palindrome Partitioning II
- POJ 3624 Charm Bracelet 01背包问题
- 梦幻西游2开店心得 日赚700万储备金
- Java中对Map(HashMap,TreeMap,Hashtable等)的排序
- HDU 3339 In Action 最短路+01背包
- 网站title该怎么进行优化
- 147_leetcode_Palindrome Partitioning II
- 8086寄存器
- 公主和王子能在一起多久的问题+dp+最长公共子序列转最长子序列。
- POJ 1321 棋盘问题
- 6.服务器与客户端双线程传输文件--客户端
- a href=#与 a href=javascript:void(0) 的区别
- malloc()与 alloc()区别
- 字符编码就是那点事 (ANSI、GBK、GB2312、UTF-8、GB18030和 UNICODE)
- which命令