题目:Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s.
解题思路:
回文划分,题目意思是给一个字符串,找出将字符串划分为一系列回文子串的各种可能组合。例如,一个子串“aab“,你需要返回["aa","b"],["a","a","b"]。这个题目的解法也是非常的典型---循环加递归,...
分类:
其他好文 时间:
2014-06-09 23:24:11
阅读次数:
256
题目
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).
For example, this binary tree is symmetric:
1
/ 2 2
/ \ / 3 4 4 3
...
分类:
其他好文 时间:
2014-06-08 18:12:04
阅读次数:
248
组合数定义:从m个不同元素中,任取n(n≤m)个元素并成一组,叫做从m个不同元素中取出n个元素的一个组合;从m个不同元素中取出n(n≤m)个元素的所有组合的个数,叫做从m个不同元素中取出n个元素的组合数。
下面是一种比较通俗的计算公式:
其递归公式为:
c(n,m)=c(n-1,m-1)+c(n-1,m)
下面是c++实现该递归算法:
#include
#include
#d...
分类:
其他好文 时间:
2014-06-08 18:06:03
阅读次数:
672
下面是参考《数据结构域算法分析》书上部分代码,结合自己理解写出的快速排序代码...
分类:
其他好文 时间:
2014-06-08 17:29:48
阅读次数:
190
1. 递归解法
/**
* Definition for binary tree
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
cl...
分类:
其他好文 时间:
2014-06-08 16:51:59
阅读次数:
199
题目
Given n, generate all structurally unique BST's (binary search trees) that store values 1...n.
For example,
Given n = 3, your program should return all 5 unique BST's shown below.
...
分类:
其他好文 时间:
2014-06-08 15:15:26
阅读次数:
223
http://poj.org/problem?id=1724
大致题意:N个城市由R条单向路连通,每条路(S,D)之间有两个因素:路的长度L和路的花费T。现要从城市1到达城市N,求花费在K以内的最短路程。
思路:很明显的dfs(他们都说很明显的spfa。。。)。不过dfs有几点注意的地方:
建立邻接表不能用vector存,要用链表的形式,采用头插法。
dfs的时候,在递归节...
分类:
其他好文 时间:
2014-06-08 14:41:32
阅读次数:
243
1. 递归解法
2. 非递归解法(空间复杂度O(n)和O(1))...
分类:
其他好文 时间:
2014-06-08 10:47:37
阅读次数:
139
题目
Given a collection of integers that might contain duplicates, S, return all possible subsets.
Note:
Elements in a subset must be in non-descending order.The solution set must not c...
分类:
其他好文 时间:
2014-06-08 05:32:21
阅读次数:
196
题目
Given a set of distinct integers, S, return all possible subsets.
Note:
Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.
...
分类:
其他好文 时间:
2014-06-08 04:01:05
阅读次数:
240