fancycarp
fancycarp
全部文章
分类
题解(44)
归档
标签
去牛客网
登录
/
注册
fancycarp的博客
全部文章
(共5篇)
NC13 #二叉树的最大深度#
最简单的DFS。 class Solution { public: int dfs(TreeNode* root) { if(root == nullptr) return 0; else return ...
DFS
2021-05-13
0
357
NC109 #岛屿数量#
最基础的DFS了。 lass Solution { public: void dfs(vector<vector<char> >& grid, int i, int j, int w, int h) { grid[i][j] = '0'...
DFS
2021-05-12
0
502
NC136 #输出二叉树的右视图#
先重构二叉树,后层次遍历。 class Solution { public: unordered_map<int, int> index; TreeNode* rebuild(vector<int>& pre, int pre_left, int pr...
DFS
递归
栈
队列
层次遍历
2021-05-12
0
440
NC121 #字符串的排列#
递归,注意判断去重。 class Solution { public: vector<string> vec; void dfs(string ans, string str) { int len = str.size(); if(...
DFS
递归
2021-05-12
0
382
NC102 #在二叉树中找到两个节点的最近公共祖先#
用DFS如果root->val等于o1或者o2,就返回o1或者o2。如果左右子树一个返回o1一个返回o2,那就返回当前节点的val,因为这就是要找的节点。如果左右子树中有某一个返回了不是-1也不是o1或o2,那就说明那底下有要找的节点,直接返回他返回的值。如果都不是就返回-1。 class S...
DFS
递归
2021-05-09
1
415