Skip to content

Instantly share code, notes, and snippets.

@lyleaf
Created December 23, 2015 10:25
Show Gist options
  • 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