# https://leetcode.com/problems/invert-binary-tree
# 시작: 2021.05.31 13:50
# 끝: 2021.05.31 23:08
# 루트-오른쪽-왼쪽 순서로 읽는다.
# bfs로 읽어나가며 좌우 반전
class Solution:
def invertTree(self, root: TreeNode) -> TreeNode:
q= deque()
if (root):
q.append(root)
while q:
for _ in range(len(q)):
node = q.popleft()
tmp = node.left
node.left = node.right
node.right = tmp
if node.left:
q.append(node.left)
if node.right:
q.append(node.right)
return root