上一页 1 2 3 4 5 6 7 8 ··· 53 下一页
摘要: // 切割 有多次迭代,把每次结果都放进vector里面,然后在对vector pop 是因为 aa b a; a aba a, 这是两种情形,但是我这里把a a 看成了一种,因此出现了问题// 所以分割仅对于 当前每种不同分割的情况,并不适用于,这种累加。 93.复原IP地址 思路: 先考虑合法的 阅读全文
posted @ 2023-07-04 09:30 博二爷 阅读(1) 评论(0) 推荐(0) 编辑
摘要: 39. 组合总和 思路: 虽然可以是重复的,但是考虑到组合没有顺序这一说,所以还是要保留startIndex, sum不要再遍历一遍,再相加,应该跟随path,一起相加 代码: 1 void combinationSum_trackBack(vector<int>& candidates, int 阅读全文
posted @ 2023-07-03 10:36 博二爷 阅读(5) 评论(0) 推荐(0) 编辑
摘要: 216.组合总和III 思路: 很像上一个组合类型的题目,唯一不同的就是自己写一个sum 代码: 1 void convertBST_cur(TreeNode* root, vector<TreeNode*>& nodes) 2 { 3 if (!root) return ; 4 if (root- 阅读全文
posted @ 2023-07-01 09:52 博二爷 阅读(1) 评论(0) 推荐(0) 编辑
摘要: 回溯——组合 思路: 套了K次的循环,如何对K次循环呢,就需要一个startIndex,用它来控制从哪里开始 代码: 1 void combine_backTrack(int n, int k, int startIndex, vector<int>& path, vector<vector<int 阅读全文
posted @ 2023-06-30 15:01 博二爷 阅读(10) 评论(0) 推荐(0) 编辑
摘要: 669. 修剪二叉搜索树 思路 递归法: 需要思考清楚,如果当前节点<low,那么就返回递归它的右节点,而不是自己取判断,找出来一个合适的节点,这样的话会越想越乱 代码: 1 TreeNode* trimBST_cursor(TreeNode* root, int low, int high) { 阅读全文
posted @ 2023-06-29 15:42 博二爷 阅读(4) 评论(0) 推荐(0) 编辑
摘要: 235. 二叉搜索树的最近公共祖先 思路: 因为是二叉搜索树,所以公共祖先一定是位于这两个节点区间中的 问题: 为什么第一个是这两个中间的例子,就是公共祖先呢?因为是最先符合要求的, 代码: 1 TreeNode* lowestCommonAncestor(TreeNode* root, TreeN 阅读全文
posted @ 2023-06-28 11:51 博二爷 阅读(1) 评论(0) 推荐(0) 编辑
摘要: 530.二叉搜索树的最小绝对差 思路: 根据二叉搜素树的特点,直接中序遍历,就是有序数组,然后两个节点进行比较,就可以 代码: 1 int getMinimumDifference(TreeNode* root) { 2 if(!root) return 0; 3 int result = INT_ 阅读全文
posted @ 2023-06-27 11:12 博二爷 阅读(3) 评论(0) 推荐(0) 编辑
摘要: 654.最大二叉树 比较简单,直接上代码 1 TreeNode* constructMax_cursor(vector<int>& nums) 2 { 3 if (nums.size() == 0) return NULL; 4 //getMaxNum 5 int index = 0; 6 int 阅读全文
posted @ 2023-06-26 11:31 博二爷 阅读(2) 评论(0) 推荐(0) 编辑
摘要: 找树左下角的值 1,层序遍历,较为简单: 1 int findBottomLeftValue_simple(TreeNode* root) { 2 int result = 0; 3 if (!root) return result; 4 queue<TreeNode*> selected; 5 s 阅读全文
posted @ 2023-06-24 10:55 博二爷 阅读(1) 评论(0) 推荐(0) 编辑
摘要: 110.平衡二叉树 (优先掌握递归) 难点: 要求每个节点的左右字数的高度相减<=1,因此,需要对每个节点都进行检查,难就难在怎么获得任意节点的高度 其中递归是最简单的: 1 int isB_cursor(TreeNode* node, bool &isBalance) 2 { 3 if (isBa 阅读全文
posted @ 2023-06-23 15:45 博二爷 阅读(3) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 ··· 53 下一页