← 返回 microsoft 的题目列表Invert Binary Tree
类型:online_judge
Given the root of a binary tree, invert the tree, and return the root of the inverted tree.
The binary tree node is defined as follows:
class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
Input Specification
The number of nodes in the tree is in the range [1, 100].
Node values are integers in the range [-100, 100].
Test Cases
Input: root = [4,2,7,1,3,6,9], Output: [4,7,2,9,6,3,1]
Input: root = [1,2], Output: [1,null,2]
Input: root = [], Output: []
Serialization Format
The input tree is serialized in level order, i.e., breadth-first traversal.
Example
Input
[4,2,7,1,3,6,9]