随笔分类 - 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
阅读全文
摘要:给定一个二叉树和所要查找的两个节点,找到两个节点的最近公共父亲节点(LCA)。比如,节点5和1的LCA是3,节点5和4的LCA是5。 class Solution { public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, Tr
阅读全文
摘要:public class Solution { public TreeNode insertNode(TreeNode root, TreeNode node) { if(root == null){ return node; } if(root.val > node.val){ //这个树里面没有
阅读全文