Leetcode 132,Palindrome Partitioning 2
来源:互联网 发布:北京理工大学网络 编辑:程序博客网 时间:2024/06/05 06:15
public int minCut(String s) { int len = s.length(); boolean[][] dp = new boolean[len][len]; int cuts[] = new int[len+1]; for (int i = 0; i < len; ++i){ cuts[i] = len - i; //cut nums from i to len [i,len] } for (int i=len-1; i>=0; i--){ for (int j=i; j<len; j++){ if ((s.charAt(i) == s.charAt(j) && (j-i<2)) || (s.charAt(i) == s.charAt(j) && dp[i+1][j-1])){ dp[i][j] = true; cuts[i] = Math.min(cuts[i], cuts[j+1]+1); } } } return cuts[0]-1; }
Refer: http://www.cnblogs.com/springfor/p/3891896.html
0 0
- Leetcode 132,Palindrome Partitioning 2
- LeetCode: Palindrome Partitioning II [132]
- LeetCode 132 Palindrome Partitioning II
- Leetcode(132) Palindrome Partitioning II
- [leetcode 132] Palindrome Partitioning II
- leetcode || 132、Palindrome Partitioning II
- leetcode 132: Palindrome Partitioning II
- 132 Palindrome Partitioning II [Leetcode]
- LeetCode #132: Palindrome Partitioning II
- Leetcode 132 Palindrome Partitioning II
- LeetCode 132 Palindrome Partitioning II
- 【leetcode】Palindrome Partitioning && Palindrome Partitioning II
- [LeetCode] Palindrome Partitioning && Palindrome Partitioning II
- LeetCode Palindrome Partitioning I&&Palindrome Partitioning II
- LeetCode Palindrome Partitioning, Palindrome Partitioning II
- [Leetcode][python]Palindrome Partitioning/Palindrome Partitioning II
- Leetcode:Palindrome Partitioning & Palindrome Partitioning II
- [leetcode-132]Palindrome Partitioning II(java)
- 第15周OJ实践12 字符串替换
- 虚拟化I/O qos——mClock算法介绍
- 【CC2541】BLE空中升级——新旧固件(imagA与imageB)的链接文件分析
- 编写Darwin的Module来支持新的流媒体文件格式
- docker容器修改并保存
- Leetcode 132,Palindrome Partitioning 2
- Android 开源框架Universal-Image-Loader解析 基本介绍及使用
- 在Fedora24/25中轻松安装gcc 4.9
- Darwin中RTSP协议的实现
- iOS_为数字键盘增加完成按钮即ToolBar
- 枚举法、穷举法
- ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'
- 【POJ 2104 K-th Number】+ 主席树
- sublime 汉化插件