Skip to content

Instantly share code, notes, and snippets.

@muddlebee
Created December 19, 2019 20:51
Show Gist options
  • Save muddlebee/f60b565d0c15d2fdb9a5622b94c3182c to your computer and use it in GitHub Desktop.
Save muddlebee/f60b565d0c15d2fdb9a5622b94c3182c to your computer and use it in GitHub Desktop.
# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution(object):
def invertTree(self, root):
"""
:type root: TreeNode
:rtype: TreeNode
"""
if root is not None:
root.left, root.right = root.right, root.left
if root is None:
return root
self.invertTree(root.left)
self.invertTree(root.right)
return root
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment