码迷,mamicode.com
首页 >  
搜索关键字:treenode    ( 1958个结果
二叉树的中序遍历
题目描述: 给定一个二叉树,返回它的中序 遍历。 输入: [1,null,2,3] 1 \ 2 / 3 输出: [1,3,2] //go //* Definition for a binary tree node. type TreeNode struct { Val int Left *TreeN ...
分类:其他好文   时间:2020-08-06 09:31:39    阅读次数:66
337. House Robber III
https://leetcode-cn.com/problems/house-robber-iii/solution/da-jia-jie-she-iii-by-leetcode-solution/ class Solution { public: unordered_map <TreeNode*, ...
分类:其他好文   时间:2020-08-05 23:24:01    阅读次数:97
leetcode7:binary-tree-preorder-traversal
题目描述 求给定的二叉树的前序遍历。 例如: 给定的二叉树为{1,#,2,3}, 1 \ 2 / 3 返回:[1,2,3]. 备注;用递归来解这道题太没有新意了,可以给出迭代的解法么? /** * struct TreeNode { * int val; * struct TreeNode *lef ...
分类:其他好文   时间:2020-08-05 13:09:09    阅读次数:71
二叉树展开为链表
前序遍历+重赋值 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * TreeNode(i ...
分类:其他好文   时间:2020-08-02 17:34:21    阅读次数:91
129求根到叶子节点数字之和
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = Nonea = TreeNode(1)b = TreeNode(2)c = TreeNode(3)a.left = ba.right = ...
分类:其他好文   时间:2020-07-29 21:25:43    阅读次数:70
leetcode-236-二叉树公共祖先
思路: 公共祖先需要分为三种情况: 1.pq包含在root的左右子树中,则root就是他们公共祖先 2.pq包含在root的右子树中,则公共祖先是右子树 3.pq包含在root的左子树中,则公共祖先在左子树 代码: /** * Definition for a binary tree node. * ...
分类:其他好文   时间:2020-07-28 17:01:57    阅读次数:59
leetcode-94-二叉树的中序遍历
思路: 中序:左->根->右 1.需要一个建立一个栈,首先将左子树放入栈中 2.获取栈顶元素并进行节点判断是否有右子树 3. 代码: /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode  ...
分类:其他好文   时间:2020-07-27 23:50:51    阅读次数:62
1530. 好叶子节点对的数量
class Solution { public int countPairs(TreeNode root, int distance) { dfs(root,0,distance); return res; } private int res = 0; public List<Integer> df ...
分类:其他好文   时间:2020-07-27 13:50:30    阅读次数:114
leetcode-----111. 二叉树的最小深度
链接:https://leetcode-cn.com/problems/minimum-depth-of-binary-tree/ 代码 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNod ...
分类:其他好文   时间:2020-07-26 19:03:29    阅读次数:62
1958条   上一页 1 ... 8 9 10 11 12 ... 196 下一页
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!