随笔分类 -  Tree

easy
摘要:class Solution { public int sumNumbers(TreeNode root) { return sum(root, 0); } private int sum(TreeNode n, int s) { if (n == null) return 0; if (n.rig 阅读全文
posted @ 2019-03-15 11:57 MarkLeeBYR 阅读(79) 评论(0) 推荐(0) 编辑
摘要:给定一个二叉树和所要查找的两个节点,找到两个节点的最近公共父亲节点(LCA)。比如,节点5和1的LCA是3,节点5和4的LCA是5。 class Solution { public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, Tr 阅读全文
posted @ 2019-03-15 11:48 MarkLeeBYR 阅读(82) 评论(0) 推荐(0) 编辑
摘要:public class Solution { public TreeNode insertNode(TreeNode root, TreeNode node) { if(root == null){ return node; } if(root.val > node.val){ //这个树里面没有 阅读全文
posted @ 2019-03-15 11:45 MarkLeeBYR 阅读(153) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示