116. Populating Next Right Pointers in Each Node You are given aperfect binary treewhereall leaves are on the same level, and every parent has two children. The binary tree has the following definition:struct Node { int val; Node *left; N...
114. Flatten Binary Tree to Linked List Given a binary tree, flatten it to a linked list in-place.For example, given the following tree: 1 / \ 2 5/ \ \3 4 6The flattened tree should look like:1\ 2 \ 3...
Java 集合 学习廖雪峰的网站中java集合部分和其他资料中集合部分的学习记录。List1、在java9中添加了List新的初始化方法:List<> list = List.of();但是使用这种方法初始化的list是定长的,不能在使用add()函数添加元素,返回的list是只读的。2、遍历list的方法最高效的是使用Iterator。public class Main {...
113. Path Sum II 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.Example:Given the below binary tree andsum = 22,...
112. Path Sum Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.Note:A leaf is a node with no children.Example:...
108. Convert Sorted Array to Binary Search Tree Given an array where elements are sorted in ascending order, convert it to a height balanced BST.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the...
106. Construct Binary Tree from Inorder and Postorder Traversal Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.For example, giveninorder =[9,3,15,20,7]postorder = [9...
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, givenpreorder =[3,9,20,15,7]inorder = [9,3...
103. Binary Tree Zigzag Level Order Traversal Given a binary tree, return thezigzag level ordertraversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).For example:Given binary tr...
98. Validate Binary Search Tree Given 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 keysless thanthe node's key. The ...
96. Unique Binary Search Trees Givenn, how many structurally uniqueBST's(binary search trees) that store values 1 ...n?Example:Input: 3Output: 5Explanation:Given n = 3, there are a total of 5 unique BST's:1 3...
102. Binary Tree Level Order Traversal Given a binary tree, return thelevel ordertraversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree[3,9,20,null,null,15,7], 3 / \ 9 20...