码迷,mamicode.com
首页 >  
搜索关键字:treenode    ( 1958个结果
力扣404. 左叶子之和
原题链接 1 class Solution: 2 ans = 0 3 def sumOfLeftLeaves(self, root: TreeNode) -> int: 4 def dfs(root,flag): 5 if not root:return 6 if not root.left and ...
分类:其他好文   时间:2021-01-26 11:58:52    阅读次数:0
剑指offer | 树的子结构 | 26
思路分析 其实就是递归判断左树和右树,但是一些判断条件需要仔细思考下. cpp /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * ...
分类:其他好文   时间:2021-01-26 11:49:40    阅读次数:0
Medium | LeetCode 114. 二叉树展开为链表
114. 二叉树展开为链表 给定一个二叉树,原地将它展开为一个单链表。 例如,给定二叉树 1 / \ 2 5 / \ \ 3 4 6 将其展开为: 1 \ 2 \ 3 \ 4 \ 5 \ 6 方法一:递归先序遍历保存进List public void flatten(TreeNode root) { ...
分类:其他好文   时间:2021-01-19 11:40:59    阅读次数:0
【刷题】二叉树
树的构造 class TreeNode: def __init__(self,val,left=None,right=None): self.val=val self.left=left self.right=right t7 = TreeNode(7) t6 = TreeNode(6) t5 = ...
分类:其他好文   时间:2021-01-14 11:27:23    阅读次数:0
LeetCode938. 二叉搜索树的范围和
题目 1 class Solution { 2 public: 3 int sum = 0; 4 int rangeSumBST(TreeNode* root, int low, int high) { 5 dfs(root,low,high); 6 return sum; 7 } 8 void d ...
分类:其他好文   时间:2021-01-14 11:04:51    阅读次数:0
剑指 Offer 28. 对称的二叉树
13分钟内递归一次性解出 思路如下: class Solution { public boolean isSymmetric(TreeNode root) { //注意可能为null if(root==null) {return true;} return mirrorTree(root.left, ...
分类:其他好文   时间:2021-01-14 10:53:52    阅读次数:0
LeetCode637. 二叉树的层平均值
题目 1 class Solution { 2 public: 3 vector<double>ans; 4 vector<double> averageOfLevels(TreeNode* root) { 5 if(!root) return ans; 6 queue<TreeNode*>q; 7 ...
分类:其他好文   时间:2021-01-13 10:58:14    阅读次数:0
LeetCode572. 另一个树的子树
题目 本题目一开始想要通过二叉树遍历KMP匹配,但看来实现比较复杂 不如直接暴力匹配,本题和LeetCode100.相同的树有共通之处 1 class Solution { 2 public: 3 bool isSubtree(TreeNode* s, TreeNode* t) { 4 if(!s ...
分类:其他好文   时间:2021-01-12 11:17:21    阅读次数:0
LeetCode_145.二叉树的后序遍历
给定一个二叉树,返回它的 后序 遍历。 示例: 输入: [1,null,2,3] 1 \ 2 / 3 输出: [3,2,1] 进阶: 递归算法很简单,你可以通过迭代算法完成吗? C 代码 ...
分类:其他好文   时间:2021-01-08 11:18:58    阅读次数:0
HashMap源码 jdk1.8
慢慢来 public class HashMap<K,V> extends AbstractMap<K,V> implements Map<K,V>, Cloneable, Serializable {} tableSizeFor(int) 根据给定的容量大小,返回指定的int类型的数,这个数是2的 ...
分类:其他好文   时间:2021-01-08 10:57:21    阅读次数:0
1958条   上一页 1 ... 3 4 5 6 7 ... 196 下一页
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!