Python | DFS | BFS
DFS Solution\n\nclass Solution:\n    def isSymmetric(self, root: Optional[TreeNode]) -> bool:\n        if not root:\n            return True\n        \n        
**DFS Solution**\n```\nclass Solution:\n    def isSymmetric(self, root: Optional[TreeNode]) -> bool:\n        if not root:\n            return True\n        \n        def dfs(l, r):\n            if not l and not r:\n                return True\n            \n            if not l or not r:\n                return False\n            \n            if l.val == r.val:\n                return dfs(l.left, r.right) and dfs(l.right, r.left)\n            \n            return False\n        \n        return dfs(root.left, root.right)\n```\n\n**BFS Solution**\n```\nclass Solution:\n    def isSymmetric(self, root: Optional[TreeNode]) -> bool:\n        if not root:\n            return True\n        \n        q = deque()\n        q.append((root.left, root.right))\n        while q:\n            for _ in range(len(q)):\n                left, right = q.popleft()\n                if not left and not right:\n                    continue\n                    \n                elif not left or not right:\n                    return False\n                \n                else:\n                    if left.val != right.val:\n                        return False\n                    \n                    q.append((left.left, right.right))\n                    q.append((left.right, right.left))\n                    \n        return True\n```\n**Please upvote if you find this helpful**
['Depth-First Search', 'Breadth-First Search', 'Python']