226. Invert Binary Tree Posted on 2021-06-05 In 面試 Views: Symbols count in article: 402 Reading time ≈ 1 mins. Given the root of a binary tree, invert the tree, and return its root. Example 1: 12Input: root = [4,2,7,1,3,6,9]Output: [4,7,2,9,6,3,1] Example 2: 12Input: root = [2,1,3]Output: [2,3,1] Example 3: 12Input: root = []Output: [] 遞迴反轉 123456T:O(2ˆn) S:O(n)class Solution: def invertTree(self, root: TreeNode) -> TreeNode: if not root: return None root.left, root.right = self.invertTree(root.right), self.invertTree(root.left) return root 如果你覺得這篇文章很棒,請你不吝點讚 (゚∀゚) Welcome to my other publishing channels RSS