MCPcopy Create free account
hub / github.com/codedecks-in/LeetCode-Solutions / Solution

Class Solution

Python/101.SymmetricTree.py:6–26  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4#Memory: 23.72%
5
6class Solution:
7 def isSymmetric(self, root: TreeNode) -> bool:
8 queue = [root]
9 while queue:
10 length = len(queue)
11 level = []
12 while length:
13 node = queue.pop(0)
14 level.append(node.val if node else None)
15 length -= 1
16 if node:
17 queue.append(node.left)
18 queue.append(node.right)
19 i = 0
20 j = len(level) - 1
21 while i <= j:
22 if level[i] != level[j]:
23 return False
24 i += 1
25 j -= 1
26 return True

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected