Skip to content

Instantly share code, notes, and snippets.

@alecchendev
Created January 9, 2021 06:08
Show Gist options
  • Save alecchendev/28c95d0b0ae1b4586087643a86412ec9 to your computer and use it in GitHub Desktop.
Save alecchendev/28c95d0b0ae1b4586087643a86412ec9 to your computer and use it in GitHub Desktop.
Invert Binary Tree Solution
class Solution:
def invertTree(self, root: TreeNode) -> TreeNode:
if not root:
return None
left = root.left
right = root.right
root.left = self.invertTree(right)
root.right = self.invertTree(left)
return root
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment