自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(19)
  • 收藏
  • 关注

原创 lc701.二叉搜索树插入

/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}...

2020-09-30 19:12:44 90

原创 lc117.填充每个节点的下一个右侧节点指针II【①->lc102层序遍历,记录每层结点数;②*****在第n层为第n+1层建立next,在n+1层通过本层next为第n+2层建立next】

①->lc102层序遍历,记录每层结点数/*// Definition for a Node.class Node {public: int val; Node* left; Node* right; Node* next; Node() : val(0), left(NULL), right(NULL), next(NULL) {} Node(int _val) : val(_val), left(NULL), right(NULL..

2020-09-28 20:02:53 101

原创 LCP23.魔术排列【洗牌】

题解https://leetcode-cn.com/problems/er94lq/solution/mo-ni-xi-pai-guo-cheng-xiang-xi-fen-xi-li-jie-kde-/主要就是分析出:k如果存在,则是唯一的。注意点:1)vector取走前k个元素:vector a(first.begin()+k,first.end());2)取偶数和奇数,取偶数位置和奇数位置:i+=2;3)如何迭代洗牌,用两个vector交替。class Solution ..

2020-09-27 21:11:25 138

原创 lc235.二叉搜索树的最近公共祖先【①分别得到祖先序列,然后比较;②***同时查找,找出分岔结点】

①分别得到祖先序列,然后比较/** * 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: TreeNode* l..

2020-09-27 17:29:15 531

原创 lc113.路径总和II【***递归,DFS】->lc78

/** * 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: vector<vector<int&g...

2020-09-27 16:18:38 118

原创 lc106.从中序与后序遍历序列构造二叉树【①与“已知后序中序,求先序”一样的左右递归方法(分而治之);②*****迭代法,原理???】->lc105

①与“已知后序中序,求先序”一样的左右递归方法(分而治之)/** * 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: ..

2020-09-25 20:12:36 135

原创 lc105.从前序与中序遍历序列构造二叉树【①与“已知后序中序,求先序”一样的左右递归方法(分而治之);②*****迭代法,原理???】

官方题解https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/solution/cong-qian-xu-yu-zhong-xu-bian-li-xu-lie-gou-zao-9/①与“已知后序中序,求先序”一样的左右递归方法(分而治之)②*****迭代法,原理???...

2020-09-25 19:52:06 224

原创 lc501.二叉搜索树中的众数【线索二叉树Morris遍历->lc538】

开始想的按普通二叉树一样,把值和计数放在一个数组里面,但是想想它是二叉搜索树,有什么特别的呢?官方题解https://leetcode-cn.com/problems/find-mode-in-binary-search-tree/solution/er-cha-sou-suo-shu-zhong-de-zhong-shu-by-leetcode-/1)先中序遍历得到顺序数组,然后遍历数组并计数。2)*****Morris遍历(中序),使用跟lc538反序中序遍历一样的方法,一边建立线索,...

2020-09-24 19:40:52 175

原创 lc617.合并二叉树【用“指针=返回结点的函数”递归连接起二叉树】

官方题解https://leetcode-cn.com/problems/merge-two-binary-trees/solution/he-bing-er-cha-shu-by-leetcode-solution/node->left=mergeTrees(t1->left,t2->left); //用=函数返回结点 递归连接起树node->right=mergeTrees(t1->right,t2->right);这样得到的是一棵由原结点和新结...

2020-09-23 20:33:20 101

原创 lc968.监控二叉树【递归,*****状态转移&树形动态规划DP(dynamic programming)】

题解一https://leetcode-cn.com/problems/binary-tree-cameras/solution/shou-hua-tu-jie-cong-di-gui-you-hua-dao-dong-tai-g/核心:由左右孩子的abc三个值,得到node的abc,如此往下递归/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *l...

2020-09-22 23:45:22 226

原创 lc.538 把二叉搜索树转换为累加树【反序中序遍历:①递归 ②*****线索二叉树Morris遍历】

官方题解https://leetcode-cn.com/problems/convert-bst-to-greater-tree/solution/ba-er-cha-sou-suo-shu-zhuan-huan-wei-lei-jia-sh-14/反序中序遍历 -递归/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * Tr...

2020-09-21 20:42:22 141

原创 lc78.子集(子集:元素相同的排列只算一个)【①**枚举 - dfs回溯法(递归法)】【②***枚举 - 用掩码表示子集(迭代法)】

官方题解https://leetcode-cn.com/problems/subsets/solution/zi-ji-by-leetcode-solution/不是很懂【每种状态需要O(n)时间构造子集】。子集枚举 - 递归法(回溯法) :cur=0,1,2的时候都会递归两次,就是含nums[cur]往后递归一次,不含nums[cur]往后递归一次,所以一共有2^n个结果。递归时深度最多为n。class Solution {public: vector&lt...

2020-09-20 21:06:54 185

原创 lc404.左叶子之和(二叉树遍历)

/** * 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 sumOfLeftLeaves(TreeNode...

2020-09-19 23:33:18 117

原创 LCP22.黑白方格画【排列组合】

关于if(k==i*n+j*n-i*j) re+=C(n,i)*C(n,j);在n行中选i个,在n列中选j个class Solution {public: int paintingPlan(int n, int k) { if(k==n*n||k==0) return 1; if(k<n) return 0; int i,j,re=0; for(i=0;i<n;+...

2020-09-19 19:44:00 291

原创 lc47.全排列II【数列含有相同数字,回溯法DFS+剪枝(剪掉相同数字相邻的排列)】

视频题解说得很清楚https://leetcode-cn.com/problems/permutations-ii/solution/hui-su-suan-fa-python-dai-ma-java-dai-ma-by-liwe-2/(我基本上就是把java翻译成c++)class Solution {public: vector<vector<int>> permuteUnique(vector<int>& nums) { ...

2020-09-18 21:09:06 202

原创 lc685.冗余连接II【和并查集有关,主要是分析附加边的几种情况】

官方题解https://leetcode-cn.com/problems/redundant-connection-ii/solution/rong-yu-lian-jie-ii-by-leetcode-solution/核心思路:class Solution {public: vector<int> findRedundantDirectedConnection(vector<vector<int>> edges){ ...

2020-09-18 19:29:30 181

原创 lc684.冗余连接【并查集】

官方题解https://leetcode-cn.com/problems/redundant-connection/solution/rong-yu-lian-jie-by-leetcode/以及并查集的实现(浙大陈老慕课)https://blog.csdn.net/sankuaizhuobu/article/details/107979957class Solution {public: vector<int> findRedundantConnection(vec...

2020-09-18 19:20:07 189

原创 lc46.全排列【回溯法,DFS】

看了这个题解,把java翻译成了c++。回溯法本质上就是DFS。class Solution {public: vector<vector<int>> permute(vector<int>& nums) { vector<vector<int>> re; int len=nums.size(); if(len==0) return re; bool us...

2020-09-18 18:53:47 192

原创 Saving James Bond - Easy Version【DFS】

7-10Saving James Bond - Easy Version(25分)This time let us consider the situation in the movie "Live and Let Die" in which James Bond, the world's most famous spy, was captured by a group of drug dealers. He was sent to a small piece of land at the cent..

2020-09-14 15:53:25 143

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除