![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
DFS
文章平均质量分 79
zhaobaoxue
这个作者很懒,什么都没留下…
展开
-
Unique Paths
方法一:DP+滚动数组。时间O(n^2),空间O(n)。转载 2014-04-07 11:23:08 · 423 阅读 · 0 评论 -
Combination Sum II
DFS,在递归树中,同一层次连续重复的元素,zhikao原创 2014-04-07 16:44:26 · 479 阅读 · 0 评论 -
DFS Search with Path Recording
Search solution using dfs while recording the current paths from the root to the current node.原创 2014-09-05 20:58:21 · 466 阅读 · 0 评论 -
Clone Graph
用一个map(unordered_map)保存原始node和新node的对应关系。转载 2014-05-29 16:42:53 · 442 阅读 · 0 评论 -
Graph Traversal (BFS vs DFS vs Stack)
BFS template: (from wiki)1 procedure BFS(G,v) is2 create a queue Q3 create a set V4 add v to V5 enqueue v onto Q6 while Q is not empty loop7 t ← Q.dequeue()转载 2014-09-11 15:56:18 · 789 阅读 · 0 评论 -
Binary Tree DFS遍历专题
Binary Tree DFS traversal contains preorder, inorder and postorder travelsals. In this article, we mea原创 2014-09-03 17:25:03 · 516 阅读 · 0 评论 -
Letter Combinations of a Phone Number
DFS遍历,时间O(3^n),空间O(n)。原创 2014-04-06 11:32:30 · 531 阅读 · 0 评论 -
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转载 2014-04-07 19:20:47 · 408 阅读 · 0 评论 -
Subsets
找出一个集合的所有子集。本题目可以利用原创 2014-04-06 12:21:09 · 520 阅读 · 0 评论 -
24点问题算法
DFS转载 2014-10-13 11:03:07 · 719 阅读 · 0 评论 -
Combination Sum
class Solution {public: vector > combinationSum(vector &candidates, int target) { sort(candidates.begin(), candidates.end()); vector > result; vector path; int sum原创 2014-04-07 16:27:51 · 396 阅读 · 0 评论 -
Sudoku Solver
Method 1: DFSclass Solution {public: void solveSudoku(vector > &board) { solveSudoku1(board); } bool solveSudoku1(vector > &board) { for(int i=0; i<9; i++)原创 2014-09-06 20:41:53 · 398 阅读 · 0 评论 -
Word Break II
使用二位bool数组来标记前去vector table[n+1];class Solution {public: vector wordBreak(string s, unordered_set &dict) { const int n = s.size(); vector table[n+1]; for(int i=1; i<=n;原创 2014-04-12 22:52:35 · 546 阅读 · 0 评论 -
Combinations
深度递归,时间复杂度O(n!),空间O(n)。class Solution {public: vector > combine(int n, int k) { vector > result; vector path; dfs(n,k,1,0, path, result); return result;转载 2014-03-30 14:02:00 · 398 阅读 · 0 评论 -
Permutations
方法一,先对利用next_permutation算法原创 2014-04-06 16:00:46 · 434 阅读 · 0 评论 -
Subsets II
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 duplica原创 2014-04-06 13:21:46 · 521 阅读 · 0 评论 -
Unique Paths II
Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as 1 and 0 respectively in the转载 2014-04-07 12:06:49 · 509 阅读 · 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 puzzle.转载 2014-04-07 15:17:47 · 459 阅读 · 0 评论 -
Restore IP Addresses
经典DFS的思路。需要注意的问题:IP地址的每一部分如果为0原创 2014-04-07 16:00:44 · 451 阅读 · 0 评论 -
Palindrome Partitioning
方法一,DFS遍历,每次保证转载 2014-04-07 11:35:20 · 384 阅读 · 0 评论 -
Generate Parentheses
class Solution {public: vector generateParenthesis(int n) { vector result; string path; dfs(n, 0, 0, path, result); return result; } void dfs(int n, int l,转载 2014-04-07 17:18:03 · 399 阅读 · 0 评论 -
Word Ladder II
与Word Ladder题目类似,转载 2014-04-06 20:30:23 · 541 阅读 · 0 评论