Leetcode#530. Minimum Absolute Difference in BST
ProblemGiven the root of a Binary Search Tree (BST), return the minimum absolute difference between the values of any two different nodes in the tree.
Example 1:
!https://assets.leetcode.com/uploads/2021/02/05/bst1.jpg
123Input: root = [4,2,6,1,3]Output: 1
Example 2:
!https://assets.leetcode.com/uploads/2021/02/05/bst2.jpg
123Input: root = [1,0,48,null,null,12,49]Output: 1
Constraints:
The number of nodes in the tree is in the range [2, 10^4].
0 <= Node.val <= 10^5
Solve法一由於有有序性質、且正整 ...
Leetcode#100. Same Tree
ProblemGiven 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.
Example 1:
!https://assets.leetcode.com/uploads/2020/12/20/ex1.jpg
123Input: p = [1,2,3], q = [1,2,3]Output: true
Example 2:
!https://assets.leetcode.com/uploads/2020/12/20/ex2.jpg
123Input: p = [1,2], q = [1,null,2]Output: false
Example 3:
!https://assets.leetcode.com/upload ...
Leetcode#117. Populating Next Right Pointers in Each Node II
leetcode116
ProblemGiven a binary tree
1234567struct Node { int val; Node *left; Node *right; Node *next;}
Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL.
Initially, all next pointers are set to NULL.
Example 1:
1234Input: root = [1,2,3,4,5,null,7]Output: [1,#,2,3,#,4,5,7,#]Explanation:Given the above binary tree (Figure A), your function should populate each next pointer to point to its next righ ...
Leetcode#116. Populating Next Right Pointers in Each Node
ProblemYou are given a perfect binary tree where all leaves are on the same level, and every parent has two children. The binary tree has the following definition:
1234567struct Node { int val; Node *left; Node *right; Node *next;}
Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL.
Initially, all next pointers are set to NULL.
Example 1:
1234Input: root = [1,2,3,4,5,6,7]Output: [1,#,2,3,#,4,5,6,7,#]E ...
Leetcode#226. Invert Binary Tree
ProblemGiven the root of a binary tree, invert the tree, and return its root.
Example 1:
123Input: root = [4,2,7,1,3,6,9]Output: [4,7,2,9,6,3,1]
Example 2:
123Input: root = [2,1,3]Output: [2,3,1]
Example 3:
123Input: root = []Output: []
Constraints:
The number of nodes in the tree is in the range [0, 100].
100 <= Node.val <= 100
Solve1234567891011121314151617181920# Definition for a binary tree node.# class TreeNode:# def __init__(self, val=0, left=None, right=None):# se ...