摘要: Q:全排列问题。DFS。 vector > permute(vector &num) { // Start typing your C/C++ solution below // DO NOT write int main() function vector > result; vector set; vector bvisited(num.size()); permute_aux(num,bvisited,set,result); return result; ... 阅读全文
posted @ 2013-08-09 14:29 summer_zhou 阅读(171) 评论(0) 推荐(0) 编辑
摘要: 求子集合C(n,k)问题;---DFS vector > combine(int n, int k) { // Start typing your C/C++ solution below // DO NOT write int main() function vector > result; if(nn) return result; vector set; subset(0,n,k,set,result); return result; } vo... 阅读全文
posted @ 2013-08-09 13:49 summer_zhou 阅读(168) 评论(0) 推荐(0) 编辑
摘要: Q: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 contain duplicate subsets.For example,IfS=[1,2,2], a solution is:[ [2], [1], [1,2,2], [2,2], [1,2], []]A: DFS问题。注意集合... 阅读全文
posted @ 2013-08-08 23:49 summer_zhou 阅读(180) 评论(0) 推荐(0) 编辑
摘要: Q: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.For example,IfS=[1,2,3], a solution is:[ [3], [1], [2], [1,2,3], [1,3], [2,3], [1,2], []]A: DFS问题。 void dfs(vecto... 阅读全文
posted @ 2013-08-08 22:11 summer_zhou 阅读(161) 评论(0) 推荐(0) 编辑
摘要: class QueueNode{public: string word; int length; QueueNode(const string& str, int l):word(str),length(l){} };class Solution {public: int ladderLength(string start, string end, unordered_set &dict) { // Start typing your C/C++ solution below // DO NOT write int main()... 阅读全文
posted @ 2013-08-08 21:07 summer_zhou 阅读(116) 评论(0) 推荐(0) 编辑
摘要: Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], [6,5,7], [4,1,8,3]]The minimum path sum from top to bottom is11(i.e.,2+3+5+1= 11).Note:Bonus point if you are a... 阅读全文
posted @ 2013-08-08 15:17 summer_zhou 阅读(152) 评论(0) 推荐(0) 编辑
摘要: Given an integern, generate a square matrix filled with elements from 1 ton2in spiral order.For example,Givenn=3,You should return the following matrix:[ [ 1, 2, 3 ], [ 8, 9, 4 ], [ 7, 6, 5 ]] vector > generateMatrix(int n) { // Start typing your C/C++ solution below // DO NOT write... 阅读全文
posted @ 2013-08-07 20:55 summer_zhou 阅读(106) 评论(0) 推荐(0) 编辑
摘要: Given a matrix ofmxnelements (mrows,ncolumns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]You should return[1,2,3,6,9,8,7,4,5].迭代递归都可以。 vector spiralOrder(vector > &matrix) { // Start typing your C/C++ so... 阅读全文
posted @ 2013-08-07 18:01 summer_zhou 阅读(134) 评论(0) 推荐(0) 编辑
摘要: Write an efficient algorithm that searches for a value in anmxnmatrix. This matrix has the following properties:Integers in each row are sorted from left to right.The first integer of each row is greater than the last integer of the previous row.For example,Consider the following matrix:[ [1, 3, ... 阅读全文
posted @ 2013-08-07 16:27 summer_zhou 阅读(147) 评论(0) 推荐(0) 编辑
摘要: Q:A family hierarchy is usually presented by a pedigree tree. Your job is to count those family members who have no child.InputEach input file contains one test case. Each case starts with a line containing 0 #includeint tree[100][100];int n,m;int count[100];int maxLevel;void dfs(int id,int level){ 阅读全文
posted @ 2013-07-13 21:39 summer_zhou 阅读(374) 评论(0) 推荐(0) 编辑