随笔分类 -  tree(recursion)

129 Sum Root to Leaf Numbers (An example is the root-to-leaf path 1->2->3 which represents the number 123.)
摘要:Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number. An example is the root-to-leaf path 1->2->3 whic 阅读全文

posted @ 2018-08-10 14:35 猪猪🐷

297. Serialize and Deserialize Binary Tree
摘要:Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or 阅读全文

posted @ 2018-08-09 18:33 猪猪🐷

Copy tree recursion / iterative
摘要:Copy tree recursion / iterative public TreeNode copy(TreeNode root){ if(root == null) return null; TreeNode newRoot = new TreeNode(root.key); newRoot.left = copy(root.left); newRoot.right ... 阅读全文

posted @ 2018-08-09 18:30 猪猪🐷

110. Balanced Binary Tree
摘要:Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as: a binary tree in which the dep 阅读全文

posted @ 2018-08-09 17:12 猪猪🐷

116. Populating Next Right Pointers in Each Node
摘要:Given a binary tree Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL 阅读全文

posted @ 2018-08-09 16:56 猪猪🐷

545. Boundary of Binary Tree
摘要:Given a binary tree, return the values of its boundary in anti-clockwise direction starting from root. Boundary includes left boundary, leaves, and ri 阅读全文

posted @ 2018-08-09 16:54 猪猪🐷

144. Binary Tree Preorder Traversal
摘要:Given a binary tree, return the preorder traversal of its nodes' values. Example: Input: [1,null,2,3] 1 \ 2 / 3 Output: [1,2,3] Follow up: Recursive s 阅读全文

posted @ 2018-07-19 12:41 猪猪🐷

94. Binary Tree Inorder Traversal
摘要:Given a binary tree, return the inorder traversal of its nodes' values. Example: Follow up: Recursive solution is trivial, could you do it iteratively 阅读全文

posted @ 2018-07-19 12:23 猪猪🐷

104. Maximum Depth of Binary Tree
摘要:Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest l 阅读全文

posted @ 2018-07-19 12:20 猪猪🐷

111. Minimum Depth of Binary Tree
摘要:Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest l 阅读全文

posted @ 2018-07-19 12:19 猪猪🐷

101. Symmetric Tree
摘要:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree [1,2,2,3,4,4,3] is symmet 阅读全文

posted @ 2018-07-19 12:18 猪猪🐷

563. Binary Tree Tilt
摘要:Given a binary tree, return the tilt of the whole tree. The tilt of a tree node is defined as the absolute difference between the sum of all left subt 阅读全文

posted @ 2018-07-19 12:17 猪猪🐷

508. Most Frequent Subtree Sum
摘要:Given the root of a tree, you are asked to find the most frequent subtree sum. The subtree sum of a node is defined as the sum of all the node values 阅读全文

posted @ 2018-07-19 12:16 猪猪🐷

543. Diameter of Binary Tree
摘要:Time Complexity: O(N) We visit every node once. Space Complexity: O(N), the size of our implicit call stack during our depth-first search. Time Comple 阅读全文

posted @ 2018-07-19 12:08 猪猪🐷

100. Same Tree
摘要:Given two binary trees, write a function to check if they are the same or not. Two binary trees are considered the same if they are structurally ident 阅读全文

posted @ 2018-07-19 12:05 猪猪🐷

250. Count Univalue Subtrees (A Uni-value subtree means all nodes of the subtree have the same value.)
摘要:Given a binary tree, count the number of uni-value subtrees. A Uni-value subtree means all nodes of the subtree have the same value. Example : 阅读全文

posted @ 2018-07-19 12:05 猪猪🐷

226. Invert Binary Tree
摘要:Invert a binary tree. Example: Input: Output: 阅读全文

posted @ 2018-07-19 12:04 猪猪🐷

导航