Palindrome Partitioning II
来源:互联网 发布:淘宝上传水印图片尺寸 编辑:程序博客网 时间:2024/05/20 18:20
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.
class Solution {public: void heapKeep(vector<int> &num,int i,int len){ int max=i; int le = 2*i; int ri = 2*i+1; if (le<len && num[le]>num[max]) max = le; if (ri<len && num[ri]>num[max]) max = ri; if (max != i) { swap(num[i],num[max]); heapKeep(num,max,len); } } void heapBuild(vector<int> &num){ int len = num.size(); for (int i=len/2; i>=0; --i){ heapKeep(num,i,len); } } void heapSort(vector<int> &num){ int len = num.size(); heapBuild(num); for (int i=len-1; i>0; --i){ swap(num[0],num[i]); heapKeep(num,0,i); } } void reserveVec(vector<int> &num,int begin,int end){ while (begin<end) { swap (num[begin++],num[end--]); } } vector<vector<int> > permuteUnique(vector<int> &num) { //从小到大 int len = num.size(); vector<vector<int>> vec; if (len==0) return vec; heapSort(num); while (true) { int index =len -1; int littlebig = index; vec.push_back(num); while (index>=1 && num[index-1]>=num[index]) { index--; } if (index==0) return vec; while (num[littlebig]<=num[index-1]){ littlebig--; } swap(num[littlebig],num[index-1]); reserveVec(num,index,len-1); } return vec; }};
0 0
- 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
- LeetCode-Palindrome Partitioning II
- [leetcode] Palindrome Partitioning II
- 数据驱动与ReactiveCocoa iOS开发
- bma250驱动
- poi Excel 设置样式
- POJ 2411 铺地砖 状态压缩dp入门
- oscache 缓存技术
- Palindrome Partitioning II
- NAND FLASH学习笔记之MTD下nand flash驱动(六)
- Android StateMachine与State学习
- java使用commons-betwixt 实现bean与xml互转
- Python学习记录
- UMTS 频谱分配
- js中cookie的使用详细分析
- 使用 sql server 2008 需要开启的服务
- 【安卓笔记】对json的解析