一、Gray Code 1 class Solution 2 { 3 public: 4 vector grayCode(int n) 5 { 6 vector result={0}; 7 if(n==0) return result; 8 ...
分类:
其他好文 时间:
2015-05-15 10:24:33
阅读次数:
139
Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.
Below is one possible representation of s1 = "great":
great
/ gr ...
分类:
编程语言 时间:
2015-04-17 11:38:26
阅读次数:
129
一: LeetCode39 Combination
Sum
题目:
Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where
the candidate numbers sums to T.
The same repeated nu...
分类:
其他好文 时间:
2015-04-12 13:28:04
阅读次数:
190
LeetCode - Given n pairs of parentheses,
write a function to generate all combinations of well-formed parentheses.
For example, given n = 3, a solution set is:
"((()))", "(()())", "(())()", "()(())", "()()()"
题解: 需要用dfs -backtracking.
给定的n为括号对,也就是有n个...
分类:
其他好文 时间:
2015-04-02 13:30:32
阅读次数:
158
(Version 0.0)这题的思路比较straightforward,可以看出会有overlapping的子问题,因此可以先按DP做法用一个二维数组存储对于某一substring是不是palindrome的判断,然后做backtracking时可以利用这个DP二维数组的结果来跳过重复的palind...
分类:
其他好文 时间:
2015-03-12 11:07:43
阅读次数:
158
Follow up for N-Queens problem.
Now, instead outputting board configurations, return the total number ofdistinct solutions.
HideTags
Backtracking
#pragma once
#include
using namespace s...
分类:
其他好文 时间:
2015-01-31 12:50:03
阅读次数:
148
题目:
Given a string s, partition s such that every substring of the partition is a palindrome.
Return all possible palindrome partitioning of s.
For example, given s = "aab",
Return
[
...
分类:
编程语言 时间:
2015-01-25 16:41:55
阅读次数:
201
题目:
Given a collection of numbers that might contain duplicates, return all possible unique permutations.
For example,
[1,1,2] have the following unique permutations:
[1,1,2], [1,2,1],
and [...
分类:
编程语言 时间:
2015-01-25 13:57:13
阅读次数:
206
题目:
Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word.
Return all such possible sentences.
For example, given...
分类:
编程语言 时间:
2015-01-20 22:22:42
阅读次数:
241
题目:
The set [1,2,3,…,n] contains a total of n! unique
permutations.
By listing and labeling all of the permutations in order,
We get the following sequence (ie, for n = 3):
"123""132""213"...
分类:
编程语言 时间:
2015-01-20 22:19:05
阅读次数:
209