深度优先搜索DFS
JohnWill_
小白一个,慢慢成长....
展开
-
Surrounded-regions 包围区域DFS
题目描述Given a 2D board containing'X'and'O', capture all regions surrounded by'X'.A region is captured by flipping all'O's into'X's in that surrounded region .For example,X X X X X O O X X X O X X O X X ...原创 2018-03-23 10:18:49 · 168 阅读 · 0 评论 -
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...原创 2018-04-19 14:28:27 · 77 阅读 · 0 评论 -
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: "((()))", "(()())", "(())()", "()(())", "...原创 2018-04-18 20:06:23 · 116 阅读 · 0 评论 -
复原二叉搜索树
题目描述Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing its structure. Note: A solution using O(n ) space is pretty straight forward. Could you devi...原创 2018-03-29 10:16:32 · 204 阅读 · 0 评论 -
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],...原创 2018-04-04 16:11:15 · 253 阅读 · 0 评论 -
subsets
题目描述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 exa...原创 2018-04-04 15:00:37 · 129 阅读 · 0 评论 -
Valid Sudoku 数独判定
题目描述Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be partially filled, where empty cells are filled with the character'.'. A partially filled s...原创 2018-04-17 09:01:51 · 203 阅读 · 0 评论 -
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 puzz...原创 2018-04-16 21:53:43 · 166 阅读 · 0 评论 -
count-and-say 计数和发言
题目描述The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221, ... 1is read off as"one 1"or11. 11is read off as"two 1s"or21. 21is read off as"one 2, then...原创 2018-04-16 20:09:59 · 5885 阅读 · 0 评论 -
maximum-depth-of-a-binary-tree
题目描述Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.实现代码: * Definition for binary tr...原创 2018-03-28 16:35:29 · 115 阅读 · 0 评论 -
combination sumII
题目描述Given a collection of candidate numbers ( C ) and a target number ( T ), find all unique combinations in C where the candidate numbers sums to T . Each number in C may only b...原创 2018-04-16 14:18:55 · 140 阅读 · 0 评论 -
permutation全排列
题目描述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...原创 2018-04-10 21:07:05 · 309 阅读 · 0 评论 -
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 number may be chose...原创 2018-04-16 10:11:51 · 90 阅读 · 0 评论 -
n-queen II
题目描述Follow up for N-Queens problem. Now, instead outputting board configurations, return the total number of distinct solutions. 实现代码: class Solution {public: int sum=0; int tot...原创 2018-04-10 15:26:36 · 193 阅读 · 0 评论 -
n-queens
题目描述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 puzzl...原创 2018-04-10 14:49:22 · 77 阅读 · 0 评论 -
二叉树最大路径和
题目描述Given a binary tree, find the maximum path sum. The path may start and end at any node in the tree. For example: Given the below binary tree, 1 / \ 2 3 Return6. 这道题是求二叉树的最...原创 2018-03-24 20:56:01 · 3678 阅读 · 0 评论 -
Regular Expression Matching 正则表达式匹配和递归
题目描述Implement regular expression matching with support for'.'and'*'.'.' Matches any single character. '*' Matches zero or more of the preceding element. The matching should cover the entire input str...原创 2018-04-21 21:12:20 · 144 阅读 · 0 评论