
回溯算法
yuccess
这个作者很懒,什么都没留下…
展开
-
51. N-Queens, leetcode
题目:The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens原创 2016-10-27 20:11:45 · 247 阅读 · 0 评论 -
77. Combinations
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.For example,If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4],]原创 2016-12-31 23:47:13 · 219 阅读 · 0 评论 -
60. Permutation Sequence
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""231""3原创 2016-12-31 22:41:10 · 218 阅读 · 0 评论 -
46, 47 Permutations I, II
1:Given a collection of distinct 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],原创 2016-12-31 10:47:48 · 232 阅读 · 0 评论 -
39,40,216 Combination Sum I II III
1:Given a set of candidate numbers (C) (without duplicates) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be原创 2016-12-31 00:06:40 · 292 阅读 · 0 评论 -
22. Generate Parentheses
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:[ "((()))", "(()())", "(())()", "()(())原创 2016-12-30 08:15:47 · 258 阅读 · 0 评论 -
17. Letter Combinations of a Phone Number
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 st原创 2016-12-28 06:25:18 · 326 阅读 · 0 评论 -
79, Word Search
Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically原创 2017-01-02 01:26:44 · 218 阅读 · 0 评论 -
113. Path Sum II 这里要注意 引用 和 传值的区别,见注释
题目:Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree and sum = 22, 5原创 2016-12-09 16:47:18 · 286 阅读 · 0 评论 -
129. Sum Root to Leaf Numbers 注意要和124题对比,都是DFS问题
题目:Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number 123.Find原创 2016-12-11 22:25:09 · 223 阅读 · 0 评论 -
37. Sudoku Solver : 代码的优化:从1865ms 到 489ms 到最后69ms AC
题目:Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character '.'.You may assume that there will be only one unique solution.初步思路:原创 2016-11-30 00:40:52 · 338 阅读 · 0 评论 -
131. Palindrome Partitioning
题目: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[ ["原创 2016-10-28 01:11:06 · 168 阅读 · 0 评论 -
90,78. Subsets II I 典型的回溯算法,另 迭代解法和 位解法
Given a set of distinct integers, nums, return all possible subsets.Note: The solution set must not contain duplicate subsets.For example,If nums = [1,2,3], a solution is:[ [3], [1],原创 2017-01-01 00:08:24 · 495 阅读 · 0 评论