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 ...
Leetcode#427. Construct Quad Tree
ProblemGiven a n * n matrix grid of 0's and 1's only. We want to represent grid with a Quad-Tree.
Return the root of the Quad-Tree representing grid.
A Quad-Tree is a tree data structure in which each internal node has exactly four children. Besides, each node has two attributes:
val: True if the node represents a grid of 1’s or False if the node represents a grid of 0’s. Notice that you can assign the val to True or False when isLeaf is False, and both are accepted in the answer.
isLea ...