LeetCode Recursion
文章平均质量分 83
Spencer_Lin
If you fight for your dream, one day....
展开
-
Permutations Java
Given a collection of numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1].Two Approac原创 2014-08-25 04:14:14 · 960 阅读 · 0 评论 -
Letter Combinations of a Phone Number Java
Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Input:Digit string原创 2014-09-14 12:38:57 · 376 阅读 · 0 评论 -
N-Queens II Java
Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.public class Solution { int res; public int to原创 2014-09-14 08:51:56 · 342 阅读 · 0 评论 -
Subsets Java
Solution: Non-Recursion method NP-Problem again. The Number of Subsets is 2(N+1) Idea: Create result list from Nothing to something that means generate from empty set to some eleme原创 2014-08-29 11:30:30 · 366 阅读 · 0 评论 -
N-Queens Java
public class Solution { public static ArrayList solveNQueens(int n) { ArrayList result = new ArrayList(); helperDFS(n,0,new int[n],result); return result;原创 2014-09-14 08:54:16 · 459 阅读 · 0 评论 -
Generate Parentheses Java
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:"((()))", "(()())", "(())()", "()(())", "()()原创 2014-08-29 10:30:24 · 569 阅读 · 0 评论 -
Restore IP Addresses Java
Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135",return ["255.255.11.135", "255.255.111.35"]. (Order原创 2014-08-28 09:30:22 · 354 阅读 · 0 评论 -
Subsets II Java
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 dupli原创 2014-08-29 11:32:04 · 389 阅读 · 0 评论 -
Combination Sum Java
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 number may be chosen from C unlimited numb原创 2014-08-25 16:35:26 · 427 阅读 · 0 评论 -
Permutations II Java
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 [2,1,1原创 2014-08-25 16:20:09 · 488 阅读 · 0 评论 -
Combinations Java
Idea: same idea as Permutations that use Loop Recursion to handle sub problem to obtain a list of Combinations. n: selection range [1...n] k: number of selection required la原创 2014-08-25 16:32:45 · 471 阅读 · 0 评论 -
Combination Sum II Java
Idea: 99% same as Combination Sum, beside, the duplication is not allow, all we need to do is to increment last selection by i+1 instead i before in Combination Sum & skip the recursion st原创 2014-08-25 16:55:36 · 448 阅读 · 0 评论 -
Palindrome Partitioning Java
Idea: Recursive-loop + dynamic programming + backtracking Combination of Longest Palindromic Substring & Word Break II There are two major steps: 1.palindromic dictionary that using sam原创 2014-09-17 14:15:10 · 307 阅读 · 0 评论