上一页 1 ··· 21 22 23 24 25 26 27 28 29 ··· 32 下一页
摘要: given a binary tree, return the preorder traversal of its nodes' values. Solution 1://非递归 Solution 1://非递归 public class Solution { public List<Integer 阅读全文
posted @ 2019-03-15 14:07 MarkLeeBYR 阅读(75) 评论(0) 推荐(0)
摘要: Given a binary tree, return the postorder traversal of its nodes' values. Solution 1: class Solution { public List<Integer> postorderTraversal(TreeNod 阅读全文
posted @ 2019-03-15 13:33 MarkLeeBYR 阅读(97) 评论(0) 推荐(0)
摘要: Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. class Solution { public TreeNode sortedL 阅读全文
posted @ 2019-03-15 13:32 MarkLeeBYR 阅读(68) 评论(0) 推荐(0)
摘要: //例如根节点为1,左2右3 class Solution { TreeNode prev = null; public void flatten(TreeNode root) {//先把最大的数设在root.right,然后剩下的数一个个往里加 if (root == null) return; 阅读全文
posted @ 2019-03-15 13:29 MarkLeeBYR 阅读(82) 评论(0) 推荐(0)
摘要: Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set toNULL. Initially, all next 阅读全文
posted @ 2019-03-15 13:25 MarkLeeBYR 阅读(75) 评论(0) 推荐(0)
摘要: //按层从左往右检索 //按层从左往右检索 //按层从左往右检索 //按层从左往右检索 public class Solution { public void connect(TreeLinkNode root) { while (root != null) { TreeLinkNode tempC 阅读全文
posted @ 2019-03-15 12:02 MarkLeeBYR 阅读(67) 评论(0) 推荐(0)
摘要: 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 阅读(84) 评论(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 阅读(87) 评论(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 阅读(158) 评论(0) 推荐(0)
摘要: /** * @param nums 输入需要去重的数组 * @return 去重后数组的长度 */public static int removeDuplicate(int[] nums) { if (nums.length == 0) { return 0; } Arrays.sort(nums) 阅读全文
posted @ 2018-11-16 22:58 MarkLeeBYR 阅读(1329) 评论(0) 推荐(0)
上一页 1 ··· 21 22 23 24 25 26 27 28 29 ··· 32 下一页