671. Second Minimum Node In a Binary Treer

Given a non-empty special binary tree consisting of nodes with the non-negative value, where each node in this tree has exactly two or zero sub-node. If the node has two sub-nodes, then this node’s value is the smaller value among its two sub-nodes. More formally, the property root.val = min(root.left.val, root.right.val) always holds. Given such a binary tree, you need to output the second minimum value in the set made of all the nodes’ value in the whole tree....

<span title='2022-01-13 00:00:00 +0000 UTC'>January 13, 2022</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

257. Binary Tree Paths

Given the root of a binary tree, return all root-to-leaf paths in any order. A leaf is a node with no children. 1 2 3 4 5 6 7 8 9 Example 1: Input: root = [1,2,3,null,5] Output: ["1->2->5","1->3"] Example 2: Input: root = [1] Output: ["1"] Constraints: The number of nodes in the tree is in the range [1, 100]. -100 <= Node.val <= 100 Solution 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 /** * Definition for a binary tree node....

<span title='2021-11-22 00:00:00 +0000 UTC'>November 22, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

1382. Balance a Binary Search Tree

Given the root of a binary search tree, return a balanced binary search tree with the same node values. If there is more than one answer, return any of them. A binary search tree is balanced if the depth of the two subtrees of every node never differs by more than 1. 1 2 3 4 5 Example 1: Input: root = [1,null,2,null,3,null,4,null,null] Output: [2,1,3,null,null,null,4] Explanation: This is not the only correct answer, [3,1,4,null,2] is also correct....

<span title='2021-11-20 00:00:00 +0000 UTC'>November 20, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

1305. All Elements in Two Binary Search Trees

Given two binary search trees root1 and root2. Return a list containing all the integers from both trees sorted in ascending order. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 Example 1: Input: root1 = [2,1,4], root2 = [1,0,3] Output: [0,1,1,2,3,4] Example 2: Input: root1 = [0,-10,10], root2 = [5,1,7,0,2] Output: [-10,0,0,1,2,5,7,10] Example 3: Input: root1 = [], root2 = [5,1,7,0,2] Output: [0,1,2,5,7] Example 4: Input: root1 = [0,-10,10], root2 = [] Output: [-10,0,10] 1 2 3 4 Example 5: Input: root1 = [1,null,8], root2 = [8,1] Output: [1,1,8,8] Constraints:...

<span title='2021-10-28 00:00:00 +0000 UTC'>October 28, 2021</span>&nbsp;·&nbsp;3 min&nbsp;·&nbsp;volyx

173. Binary Search Tree Iterator

Implement the BSTIterator class that represents an iterator over the in-order traversal of a binary search tree (BST): BSTIterator(TreeNode root) Initializes an object of the BSTIterator class. The root of the BST is given as part of the constructor. The pointer should be initialized to a non-existent number smaller than any element in the BST. boolean hasNext() Returns true if there exists a number in the traversal to the right of the pointer, otherwise returns false....

<span title='2021-10-28 00:00:00 +0000 UTC'>October 28, 2021</span>&nbsp;·&nbsp;3 min&nbsp;·&nbsp;volyx

314. Binary Tree Vertical Order Traversal

314. Binary Tree Vertical Order Traversal Given the root of a binary tree, return the vertical order traversal of its nodes’ values. (i.e., from top to bottom, column by column). If two nodes are in the same row and column, the order should be from left to right. 1 2 3 4 Example 1: Input: root = [3,9,20,null,null,15,7] Output: [[9],[3,15],[20],[7]] 1 2 3 4 Example 2: Input: root = [3,9,8,4,0,1,7] Output: [[4],[9],[3,0,1],[8],[7]] 1 2 3 4 Example 3: Input: root = [3,9,8,4,0,1,7,null,null,null,2,5] Output: [[4],[9,5],[3,0,1],[8,2],[7]] 1 2 3 4 Example 4: Input: root = [] Output: [] Constraints:...

<span title='2021-07-22 00:00:00 +0000 UTC'>July 22, 2021</span>&nbsp;·&nbsp;3 min&nbsp;·&nbsp;volyx

987. Vertical Order Traversal of a Binary Tree

987. Vertical Order Traversal of a Binary Tree Given the root of a binary tree, calculate the vertical order traversal of the binary tree. For each node at position (row, col), its left and right children will be at positions (row + 1, col - 1) and (row + 1, col + 1) respectively. The root of the tree is at (0, 0). The vertical order traversal of a binary tree is a list of top-to-bottom orderings for each column index starting from the leftmost column and ending on the rightmost column....

<span title='2021-07-22 00:00:00 +0000 UTC'>July 22, 2021</span>&nbsp;·&nbsp;6 min&nbsp;·&nbsp;volyx

515. Find Largest Value in Each Tree Row

515. Find Largest Value in Each Tree Row Given the root of a binary tree, return an array of the largest value in each row of the tree (0-indexed). 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 Example 1: Input: root = [1,3,2,5,3,null,9] Output: [1,3,9] Example 2: Input: root = [1,2,3] Output: [1,3] Example 3: Input: root = [1] Output: [1] Example 4: Input: root = [1,null,2] Output: [1,2] Example 5: Input: root = [] Output: [] Constraints:...

<span title='2021-07-19 00:00:00 +0000 UTC'>July 19, 2021</span>&nbsp;·&nbsp;3 min&nbsp;·&nbsp;volyx

144. Binary Tree Preorder Traversal

144. Binary Tree Preorder Traversal Given the root of a binary tree, return the preorder traversal of its nodes’ values. 1 2 3 4 Example 1: Input: root = [1,null,2,3] Output: [1,2,3] 1 2 3 4 Example 2: Input: root = [] Output: [] 1 2 3 4 Example 3: Input: root = [1] Output: [1] 1 2 3 4 Example 4: Input: root = [1,2] Output: [1,2] 1 2 3 4 Example 5: Input: root = [1,null,2] Output: [1,2] Constraints:...

<span title='2021-03-16 00:00:00 +0000 UTC'>March 16, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

108. Convert Sorted Array to Binary Search Tree

108. Convert Sorted Array to Binary Search Tree Given an integer array nums where the elements are sorted in ascending order, convert it to a height-balanced binary search tree. A height-balanced binary tree is a binary tree in which the depth of the two subtrees of every node never differs by more than one. 1 2 3 4 5 Example 1: Input: nums = [-10,-3,0,5,9] Output: [0,-3,9,-10,null,5] Explanation: [0,-10,5,null,-3,null,9] is also accepted: 1 2 3 4 5 Example 2: Input: nums = [1,3] Output: [3,1] Explanation: [1,3] and [3,1] are both a height-balanced BSTs....

<span title='2021-03-13 00:00:00 +0000 UTC'>March 13, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

110. Balanced Binary Tree

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 left and right subtrees of every node differ in height by no more than 1. 1 2 3 4 Example 1: Input: root = [3,9,20,null,null,15,7] Output: true 1 2 3 4 Example 2: Input: root = [1,2,2,3,3,null,null,4,4] Output: false 1 2 3 4 Example 3: Input: root = [] Output: true Constraints:...

<span title='2021-03-13 00:00:00 +0000 UTC'>March 13, 2021</span>&nbsp;·&nbsp;3 min&nbsp;·&nbsp;volyx

111. Minimum Depth of Binary Tree

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 leaf node. Note: A leaf is a node with no children. 1 2 3 4 Example 1: Input: root = [3,9,20,null,null,15,7] Output: 2 1 2 3 4 Example 2: Input: root = [2,null,3,null,4,null,5,null,6] Output: 5 Constraints:...

<span title='2021-03-12 00:00:00 +0000 UTC'>March 12, 2021</span>&nbsp;·&nbsp;3 min&nbsp;·&nbsp;volyx

100. Same Tree

![https://leetcode.com/problems/same-tree/] Given the roots of two binary trees p and q, write a function to check if they are the same or not. Two binary trees are considered the same if they are structurally identical, and the nodes have the same value. 1 2 3 4 Example 1: Input: p = [1,2,3], q = [1,2,3] Output: true 1 2 3 4 Example 2: Input: p = [1,2], q = [1,null,2] Output: false 1 2 3 4 Example 3: Input: p = [1,2,1], q = [1,1,2] Output: false Constraints:...

<span title='2021-03-11 00:00:00 +0000 UTC'>March 11, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

101. Symmetric Tree

!()[https://leetcode.com/problems/symmetric-tree/] Given the root of a binary tree, check whether it is a mirror of itself (i.e., symmetric around its center). 1 2 3 4 Example 1: Input: root = [1,2,2,3,4,4,3] Output: true 1 2 3 4 Example 2: Input: root = [1,2,2,null,3,null,3] Output: false Constraints: The number of nodes in the tree is in the range [1, 1000]. -100 <= Node.val <= 100 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 /** * Definition for a binary tree node....

<span title='2021-03-11 00:00:00 +0000 UTC'>March 11, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

104. Maximum Depth of Binary Tree

104. Maximum Depth of Binary Tree Given the root of a binary tree, return its maximum depth. A binary tree’s maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. 1 2 3 4 Example 1: Input: root = [3,9,20,null,null,15,7] Output: 3 1 2 3 4 Example 2: Input: root = [1,null,2] Output: 2 1 2 3 4 Example 3: Input: root = [] Output: 0 1 2 3 4 Example 4: Input: root = [0] Output: 1 Constraints:...

<span title='2021-03-11 00:00:00 +0000 UTC'>March 11, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx