随笔分类 -  tree(recursion)

298. Binary Tree Longest Consecutive Sequence
摘要:Given a binary tree, find the length of the longest consecutive sequence path. The path refers to any sequence of nodes from some starting node to any 阅读全文

posted @ 2018-12-11 06:38 猪猪🐷

549. Binary Tree Longest Consecutive Sequence II
摘要:Given a binary tree, you need to find the length of Longest Consecutive Path in Binary Tree. Especially, this path can be either increasing or decreasing. For example, [1,2,3,4] and [4,3,2,1] are bot... 阅读全文

posted @ 2018-11-30 13:45 猪猪🐷

105. Construct Binary Tree from Preorder and Inorder Traversal
摘要:Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree. For example, given preorder = [3,9,20,15,7] inorder = [9,3... 阅读全文

posted @ 2018-11-09 10:35 猪猪🐷

337. House Robber III
摘要:In step I, we defined our problem as rob(root), which will yield the maximum amount of money that can be robbed of the binary tree rooted at root. Thi 阅读全文

posted @ 2018-11-09 06:42 猪猪🐷

428. Serialize and Deserialize N-ary 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-11-08 16:23 猪猪🐷

872. Leaf-Similar Trees
摘要:Consider all the leaves of a binary tree. From left to right order, the values of those leaves form a leaf value sequence. For example, in the given t 阅读全文

posted @ 2018-11-08 16:16 猪猪🐷

606. Construct String from Binary Tree
摘要:You need to construct a string consists of parenthesis and integers from a binary tree with the preorder traversing way. The null node needs to be represented by empty parenthesis pair "()". And you ... 阅读全文

posted @ 2018-11-08 02:05 猪猪🐷

671. Second Minimum Node In a Binary Tree
摘要:Given a non-empty special binary tree consisting of nodes with the non-negative value, where each node in this tree has exactly twoor zero sub-node. If the node has two sub-nodes, then this node's va... 阅读全文

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

515. Find Largest Value in Each Tree Row
摘要:You need to find the largest value in each row of a binary tree. Example: Input: 1 / \ 3 2 / \ \ 5 3 9 Output: [1, 3, 9] Bfs public int[] findV... 阅读全文

posted @ 2018-11-07 05:14 猪猪🐷

662. Maximum Width of Binary Tree
摘要:Given a binary tree, write a function to get the maximum width of the given tree. The width of a tree is the maximum width among all levels. The binary tree has the same structure as a full binary tr... 阅读全文

posted @ 2018-11-07 05:13 猪猪🐷

652. Find Duplicate Subtrees
摘要:Given a binary tree, return all duplicate subtrees. For each kind of duplicate subtrees, you only need to return the root node of any one of them. Two trees are duplicate if they have the same struct... 阅读全文

posted @ 2018-11-07 05:10 猪猪🐷

572. Subtree of Another Tree
摘要:, 3, 4, 1, #, #, 2, 0, #, #, #, 5, #, # , 4, 1, #, #, 2, #, # , 3, 4, 1, #, #, 2, #, #, 5, #, # 阅读全文

posted @ 2018-11-07 05:10 猪猪🐷

Tweaked Identical Binary Tree
摘要:1 1 / \ / \ 2 3 and 3 2 / \ 4 4 是扭转后可等价的二叉树。 1 1 / \ / \ 2 3 and 3 2 / / 4 4 作者:Jason_Yuan链接:https://www.jianshu.com/p/0623cf8ad71b來源:简书简书著作权归作者所有,任何形 阅读全文

posted @ 2018-08-28 20:08 猪猪🐷

617. Merge Two Binary Trees
摘要:Approach #2 Iterative Method [Accepted] Algorithm In the current approach, we again traverse the two trees, but this time we make use of a stackstack  阅读全文

posted @ 2018-08-28 20:06 猪猪🐷

find the length of shortest path between two nodes in a tree
摘要:https://www.geeksforgeeks.org/shortest-path-between-two-nodes-in-array-like-representation-of-binary-tree/ 阅读全文

posted @ 2018-08-11 04:53 猪猪🐷

236. Lowest Common Ancestor of a Binary Tree
摘要:time complexity is O(n) Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According to the definition of LCA 阅读全文

posted @ 2018-08-11 04:52 猪猪🐷

112. Path Sum
摘要:112. Path Sum https://www.youtube.com/watch?v=zdClzfnkvDY Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that addin 阅读全文

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

124. Binary Tree Maximum Path Sum
摘要:124. Binary Tree Maximum Path Sum https://github.com/tongzhang1994/Facebook-Interview-Coding/blob/master/Longest%20Path%20in%20Binary%20Tree.java http 阅读全文

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

437 Path Sum III (Find the number of paths that sum to a given value.)
摘要:You are given a binary tree in which each node contains an integer value. Find the number of paths that sum to a given value. The path does not need t 阅读全文

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

113. Path Sum II (find all root-to-leaf paths where each path's sum equals the given sum.)
摘要:Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum. Note: A leaf is a node with no children. Exampl 阅读全文

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

导航