House Robber III
House Robber IIIThe thief has found himself a new place for his thievery again. There is only one entrance to this area, called the “root.” Besides the root, each house has one and only one parent ho
House Robber IIIThe thief has found himself a new place for his thievery again. There is only one entrance to this area, called the “root.” Besides the root, each house has one and only one parent ho
Kth Smallest Element in a BSTGiven a binary search tree, write a function kthSmallest to find the kth smallest element in it. Note: You may assume k is always valid, 1 ? k ? BST’s total elements. Fol
Binary Tree Right Side ViewGiven a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom. For example:Given the followi
Binary Tree Preorder TraversalGiven a binary tree, return the preorder traversal of its nodes’ values. For example:Given binary tree {1,#,2,3}, 123451 \ 2 /3 return [1,2,3]. Note: Recursive solution
Sum Root to Leaf NumbersGiven 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 which represents the nu
Flatten Binary Tree to Linked ListGiven a binary tree, flatten it to a linked list in-place. For example:Given 12345 1 / \ 2 5 / \ \3 4 6 The flattened tree should look like: 1234567891
Path Sum IIGiven a binary tree and a sum, find all root-to-leaf paths where each path’s sum equals the given sum. For example:Given the below binary tree and sum = 22, 1234567 5 / \ 4 8
Convert Sorted Array to Binary Search TreeGiven an array where elements are sorted in ascending order, convert it to a height balanced BST. 提示 解題應用 DepthFirstSearch InorderTravel Default:12
Construct Binary Tree from Inorder and Postorder TraversalGiven inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree.
Construct Binary Tree from Preorder and Inorder TraversalGiven preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree. 提
Binary Tree Zigzag Level Order TraversalGiven a binary tree, return the zigzag level order traversal of its nodes’ values. (ie, from left to right, then right to left for the next level and alternate
Validate Binary Search TreeGiven a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less
Unique Binary Search Trees IIGiven an integer n, generate all structurally unique BST’s (binary search trees) that store values 1…n. For example:Given n = 3, your program should return all 5 unique B
Unique Binary Search TreesGiven n, how many structurally unique BST’s (binary search trees) that store values 1…n? For example:Given n = 3, there are a total of 5 unique BST’s. 123451 3 3
Binary Tree Inorder TraversalGiven a binary tree, return the inorder traversal of its nodes’ values. For example:Given binary tree [1,null,2,3], 123451 \ 2 /3 return [1,3,2]. Note: Recursive solutio
Find Mode in Binary Search TreeGiven a binary search tree (BST) with duplicates, find all the mode(s) (the most frequently occurred element) in the given BST. Assume a BST is defined as follows: The
Path Sum IIIYou 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 to start or end at the root or a leaf,
Sum of Left LeavesFind the sum of all left leaves in a given binary tree. For Example:1234567 3 / \ 9 20 / \ 15 7There are two left leaves in the binary tree, with values 9 and 15 resp
Binary Tree PathsGiven a binary tree, return all root-to-leaf paths. For example, given the following binary tree: 12345 1 / \2 3 \ 5 All root-to-leaf paths are: 1["1->2->5",
Invert Binary TreeInvert a binary tree. 12345 4 / \ 2 7 / \ / \1 3 6 9 to 12345 4 / \ 7 2 / \ / \9 6 3 1 提示 解題應用 Tree 樹的遍歷方式 Default:1234567891011/** *
Minimum Depth of Binary TreeGiven 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 leaf node. 提示 解題應用