---
# System prepended metadata

title: Leetcode ---  Symmetric Tree (unedited)
tags: [BFS, leetcode, queue, medium, tree]

---

# Leetcode ---  Symmetric Tree (unedited)


## 101. Symmetric Tree
### Description:
Given the root of a binary tree, check whether it is a mirror of itself (i.e., symmetric around its center).

:::info

:::
:::warning

:::

![](https://i.imgur.com/W9lrMxr.png)


### 解法條列
1.  暴力解

### 解法細節

:::success
level search(BFS)
queue
:::


### Python Solution
解
```python=
# 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 isSymmetric(self, root: Optional[TreeNode]) -> bool:
        queue = [root]
        temp_queue = []
        level = []
        while(queue):
            node = queue.pop()
            if(not node):
                level.append(None)
                if(not queue):
                    if(not (level == level[::-1])):
                        return False
                    queue, temp_queue = temp_queue, queue
                    level.clear()
                continue
            level.append(node.val)
            temp_queue.insert(0,node.left)
            temp_queue.insert(0,node.right)
            if(not queue):
                if(not (level == level[::-1])):
                    return False
                queue, temp_queue = temp_queue, queue
                level.clear()
                
        if(not (level == level[::-1])):
            return False
        return True
```


---
```python=3

```

---
```python=8


```

---
```python=9    

```


---
```python=15   

```


---






###### tags: `leetcode` `tree` `medium` `queue` `BFS`