树
Data Structures & Algorithms · 23 notes
- Implement Trie (Prefix Tree)historical
Implement a Trie (prefix tree) with the three operations insert, search, and startsWith.
- Unique Binary Search Treeshistorical
Given an integer n, determine how many binary search trees can be formed using nodes 1 ... n.
- Binary Tree Inorder Traversalhistorical
Given the root root of a binary tree, return its inorder traversal.
- Construct Binary Tree from Preorder and Inorder Traversalhistorical
Construct a binary tree from its preorder traversal and inorder traversal.
- Binary Tree Preorder, Inorder, and Postorder Traversalhistorical
Print all nodes of a binary tree in preorder, inorder, and postorder respectively.
- Convert BST to Greater Treehistorical
Given the root of a binary search tree whose node values are distinct, convert it to a Greater Sum Tree so that the new value of each node equals the sum of all values in the original tree that are greater than or equal to node.val.
- Validate Binary Search Treehistorical
Given a binary tree, determine whether it is a valid binary search tree.
- Flatten Binary Tree to Linked Listhistorical
Flatten a binary tree in place into a linked list whose node order follows the tree's preorder traversal.
- Lowest Common Ancestor of a Binary Treehistorical
Given a binary tree, find the lowest common ancestor of two specified nodes in the tree.
- Diameter of Binary Treehistorical
Given a binary tree, calculate its diameter. The diameter of a binary tree is the maximum path length between any two nodes. This path may or may not pass through the root.
- Lowest Common Ancestor Nodehistorical
Given a binary tree and two nodes o1 and o2 in the tree, find their lowest common ancestor.
- Merge Two Binary Treeshistorical
Merge two binary trees by adding the values of overlapping nodes and retaining nodes that do not overlap.
- House Robber IIIhistorical
Houses form a binary tree, and a parent and its child cannot both be robbed. Choose houses that maximize the total amount stolen.
- Sum Root to Leaf Numbershistorical
Each binary-tree node contains a digit from 0 to 9. Root-to-leaf paths form integers; return their total sum.
- Path Sum IIIhistorical
Count downward paths in an integer-valued binary tree whose sum equals a target. Paths need not start at the root or end at a leaf.
- Binary Tree Maximum Path Sumhistorical
A path in a binary tree may connect any nodes through parent-child edges. Find the nonempty path with the largest sum of node values.
- Binary Tree Right Side Viewhistorical
Given a binary tree, imagine standing on its right side. Return the values of the nodes visible from the right, ordered from top to bottom.
- Binary Tree Level Order Traversalhistorical
Given a binary tree, return the node values obtained by level-order traversal (that is, visit all nodes level by level from left to right).
- Serialize and Deserialize Binary Treehistorical
Serialization converts a data structure or object into a continuous representation so the result can be stored in a file or memory, transmitted over a network, and later reconstructed by the reverse operation.
- Binary Tree Zigzag Level Order Traversalhistorical
Given the root root of a binary tree, return the zigzag level-order traversal of its node values (left to right on one level, then right to left on the next, alternating between levels).