Skip to content

Instantly share code, notes, and snippets.

@lyleaf
Created December 23, 2015 10:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lyleaf/bc75b359a061e21a9601 to your computer and use it in GitHub Desktop.
Save lyleaf/bc75b359a061e21a9601 to your computer and use it in GitHub Desktop.
Python Algorithms
#
# 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 not root:
return
root.left, root.right = root.right, root.left
map(self.invertTree, (root.left,root.right))
return root
Change value use tuple.
Use map.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment