invert-bt py3

This commit is contained in:
2022-04-25 03:35:12 +05:30
parent 11967da94a
commit e793d395bd
2 changed files with 46 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def invertTree(self, root: Optional[TreeNode]) -> Optional[TreeNode]:
if root is None: return None
root.left, root.right = root.right, root.left
self.invertTree(root.left)
self.invertTree(root.right)
return root