Closed labuladong closed 1 year ago
# Aug 16
# LC Invert Tree
# recusive solution is straightforward
# traverse solution do inversion and then traverse
class Solution:
def invertTree(self, root: Optional[TreeNode]) -> Optional[TreeNode]:
if not root:
return
left = self.invertTree(root.left)
right = self.invertTree(root.right)
root.left = right
root.right = left
return root
本期打卡已结算完成。报名最新一期的打卡活动 点这里