#226
Invert Binary Tree
easy· Treesruns: 0Given the root of a binary tree, invert the tree by swapping the left and right children of every node, and return its root.
sign in to paste and practice your own solution
wpm 0acc 100%time 0:000 / 274
class Solution:
def invertTree(self, root: TreeNode | None) -> TreeNode | None:
if not root:
return None
root.left, root.right = (
self.invertTree(root.right),
self.invertTree(root.left),
)
return root
click the box to focus · tab inserts 4 spaces · backspace to correct · esc to pause
desktop only
codedrill is a typing game and needs a real keyboard. open this on a laptop or desktop to practice.
you can still browse problems and sections from your phone.