DFS
DFS
lucky tiger
要一直前进,一直静下心来学习。
展开
-
力扣115不同的子序列2(记忆化搜索-DFS)
直接递归DFS超时 class Solution { public: int dfs(string s,int idx, string t,int tmp) { if(tmp == t.size()) { return 1; } if(idx == s.size()) { return 0; } if(s[idx] == t[tm原创 2021-03-24 10:23:00 · 146 阅读 · 0 评论 -
力扣529扫雷游戏 DFS
1、dfs递归8个方向 1、如果一个地雷('M')被挖出,游戏就结束了- 把它改为 'X'。 2、如果一个没有相邻地雷的空方块('E')被挖出,修改它为('B'),并且所有和其相邻的未挖出方块都应该被递归地揭露。 3、如果一个至少与一个地雷相邻的空方块('E')被挖出,修改它为数字('1'到'8'),表示相邻地雷的数量。 如果在此次点击中,若无更多方块可被揭露,则返回面板。 class Solution { public: vector<vector<char>> ..原创 2020-08-20 16:14:23 · 131 阅读 · 0 评论 -
力扣93.复原IP地址 回溯+剪枝(细节有点多,慢慢想)
1、"25525511135" 2、25、255 记录现在点的个数和上一个点位置 class Solution { public: vector<string> res; vector<string> restoreIpAddresses(string s) { int n = s.size(); string cur = s; helper(n,0,-1,cur,s); return res;原创 2020-08-13 09:44:13 · 243 阅读 · 1 评论 -
130、被围绕的区域 DFS变种
1、 2、这是一道dfs问题 把所有边上的O变为A并DFS其上下左右的相连的O变为A,后面这些A要变成O 其余O变为X class Solution { public: int n, m; void dfs(vector<vector<char>>& board, int x, int y) { if (x < 0 || x >= n || y < 0 || y >= m || board[x][y] !原创 2020-08-11 20:51:09 · 130 阅读 · 0 评论 -
力扣207课程表力扣210课程表II(图 + DFS)
207 https://leetcode-cn.com/problems/course-schedule/ 210 https://leetcode-cn.com/problems/course-schedule-ii/ class Solution { private: vector<vector<int>> edges;//建立一个邻接表 vector<int> visited;//0未搜索,1搜索中,2搜索完 vector<int原创 2020-08-04 15:32:42 · 231 阅读 · 0 评论 -
力扣 面试题II平衡二叉树
进程与线程的区别,一个是上面所说的进程中可以有多个线程。第二个就是线程没有自己的资源,没有自己的地址空间,必须要依附于进程的地址空间中才可以运行。原创 2020-05-31 22:11:01 · 186 阅读 · 0 评论 -
力扣534 二叉树直径 递归
1、 2、 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Solution { int ans=0; public: int d原创 2020-05-23 20:41:21 · 133 阅读 · 0 评论 -
力扣1022 从根到叶的二叉树之和 递归
1、 2、 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Solution { public: const long num=1e9+7原创 2020-05-23 16:38:54 · 121 阅读 · 0 评论 -
力扣993 二叉树堂兄弟节点 递归+DFS
1、 2、 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Solution { public: int xdepth=-1; i原创 2020-05-21 19:33:53 · 180 阅读 · 0 评论 -
dfs 力扣630 比较绕的一道题
1、 /* // Definition for Employee. class Employee { public: int id; int importance; vector<int> subordinates; }; */ class Solution { public: int getImportance(vector<E...原创 2020-05-03 20:36:09 · 105 阅读 · 0 评论 -
DFS
1、 递归: /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} *...原创 2020-04-29 09:36:54 · 401 阅读 · 0 评论