text: """
  [226. Invert Binary Tree](https://leetcode.com/problems/invert-binary-tree/)
  
  Invert a binary tree.
  
  Example:
  
  Input:
  
       4
     /   \
    2     7
   / \   / \
  1   3 6   9
  Output:
  
       4
     /   \
    7     2
   / \   / \
  9   6 3   1
  Trivia:
  
  This problem was inspired by this original tweet by Max Howell:
  
  Google: 90% of our engineers use the software you wrote (Homebrew), but you can’t invert a binary tree on a whiteboard
  so f*** off.
  
  """
  
  
  # Definition for a binary tree node.
  # class TreeNode:
  #     def __init__(self, x):
  #         self.val = x
  #         self.left = None
  #         self.right = None
  
  
  class Solution:
      def invertTree(self, root: TreeNode) -> TreeNode:
          if not root:
              return
          if root:
              root.left, root.right = root.right, root.left
              self.invertTree(root.left)
              self.invertTree(root.right)
              return root
  
  
  # Runtime: 32 ms, faster than 29.77% of Python3 online submissions
  # Memory Usage: 12.9 MB, less than 100.00% of Python3 online submissions
  