这几题都能用bfs + queue
- initialize res list and q queue
- use while loop to check if q is not empty
- use for loop with range(qLen) to iterate through elements in each level of the tree
- pop and store the node using popleft()
- check if node exists, if it does
- append its left and right children to the q
还是卡卡的,要注意:
- while loop 进下个level时要清空level list
- 在每个level要对pop出来的node进行操作前要先检查node 不为空