题目链接:https://leetcode-cn.com/problems/same-tree/ 思路:同时深搜或广搜两棵树,比较值即可 class Solution { public boolean isSameTree(TreeNode p, TreeNode q) { //100 5 if(p ...
分类:
其他好文 时间:
2020-08-07 09:43:32
阅读次数:
51
题目描述: 给定一个二叉树,返回它的中序 遍历。 输入: [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
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
题目描述 求给定的二叉树的前序遍历。 例如: 给定的二叉树为{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
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
思路: 公共祖先需要分为三种情况: 1.pq包含在root的左右子树中,则root就是他们公共祖先 2.pq包含在root的右子树中,则公共祖先是右子树 3.pq包含在root的左子树中,则公共祖先在左子树 代码: /** * Definition for a binary tree node. * ...
分类:
其他好文 时间:
2020-07-28 17:01:57
阅读次数:
59
思路: 中序:左->根->右 1.需要一个建立一个栈,首先将左子树放入栈中 2.获取栈顶元素并进行节点判断是否有右子树 3. 代码: /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode ...
分类:
其他好文 时间:
2020-07-27 23:50:51
阅读次数:
62
找开例子: https://github.com/xiaoruilin/EasyUI_Plug 复制到地址为: https://github.com/xiaoruilin/EasyUI_Plug.git 组织地址为: https://github.com/xiaoruilin/EasyUI_Plug ...
分类:
其他好文 时间:
2020-07-27 13:55:01
阅读次数:
80