
Backtracking
文章平均质量分 75
dyllanzhou
这个作者很懒,什么都没留下…
展开
-
[Leetcode]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:"((()))", "(()())", "(())()", "()(())", "()()()"原创 2015-09-24 17:26:35 · 306 阅读 · 0 评论 -
[Leetcode]Permutations II
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].原创 2015-10-28 00:12:08 · 416 阅读 · 0 评论 -
[Leetcode]Gray Code
The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the sequence of gr原创 2015-09-23 18:40:12 · 296 阅读 · 0 评论 -
[Leetcode]Subsets II
Given a collection of integers that might contain duplicates, nums, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain dupl原创 2015-10-13 20:10:03 · 265 阅读 · 0 评论 -
[Leetcode]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 string原创 2015-10-27 21:34:48 · 346 阅读 · 0 评论 -
[Leetcode]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 n原创 2015-11-13 21:30:03 · 191 阅读 · 0 评论 -
[Leetcode]N-Queens
The n-queens puzzle is the problem of placing n queens on ann×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens puzzle.Ea原创 2015-12-15 16:55:08 · 268 阅读 · 0 评论 -
[Leetcode]N-Queens II
Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.class Solution {public: /*algorithm: DFS */ vectorgetNex原创 2015-12-15 17:22:33 · 295 阅读 · 0 评论 -
[Leetcode]Remove Invalid Parentheses
Remove the minimum number of invalid parentheses in order to make the input string valid. Return all possible results.Note: The input string may contain letters other than the parentheses ( and).原创 2016-01-14 20:14:43 · 345 阅读 · 0 评论 -
[Leetcode]Sudoku Solver
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.A sudoku puzzle.原创 2016-03-10 19:42:23 · 304 阅读 · 0 评论 -
[Leetcode]Combination Sum
Given a set of candidate numbers (C) and a target number (T), find all unique combinations inC where the candidate numbers sums to T.The same repeated number may be chosen from C unlimited numbe原创 2015-10-12 21:37:19 · 284 阅读 · 0 评论 -
[Leetcode]Subsets
Given a set of distinct integers, nums, 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,原创 2015-10-12 15:48:51 · 356 阅读 · 0 评论 -
[Leetcode]Permutations
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].class Solution原创 2015-10-01 16:22:40 · 225 阅读 · 0 评论 -
[Leetcode]Combination Sum II
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations inC where the candidate numbers sums to T.Each number in C may only be used once in the combinatio原创 2015-11-04 15:45:14 · 227 阅读 · 0 评论 -
[Leetcode]Combinations
Given two integers n and k, return all possible combinations ofk 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],]原创 2015-10-08 18:06:27 · 294 阅读 · 0 评论 -
[Leetcode]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 [ ["aa","b"],原创 2015-10-24 15:03:39 · 266 阅读 · 0 评论 -
[Leetcode]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""312""原创 2015-11-09 22:49:19 · 268 阅读 · 0 评论 -
[Leetcode]Palindrome Partitioning II
Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning of s.For example, given s = "aab",Return 1 s原创 2015-10-25 18:13:55 · 286 阅读 · 0 评论 -
[Leetcode]Combination Sum III
Find all possible combinations of k numbers that add up to a numbern, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.Ensure that numbers wit原创 2015-10-11 11:37:04 · 301 阅读 · 0 评论 -
[Leetcode]Restore IP Addresses
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 does原创 2015-11-12 11:59:16 · 203 阅读 · 0 评论 -
[Leetcode]Jump Game
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine if原创 2015-10-26 19:54:14 · 367 阅读 · 0 评论 -
[Leetcode]Longest Increasing Path in a Matrix
Given an integer matrix, find the length of the longest increasing path.From each cell, you can either move to four directions: left, right, up or down. You may NOT move diagonally or move outside o原创 2016-03-14 14:49:11 · 356 阅读 · 0 评论