树的递归遍历,DFS遍历和BFS遍历
问题
https://leetcode.com/problems/same-tree/
Given two binary trees, write a function to check if they are the same or not.
Two binary trees are considered the same if they are structurally identical and the nodes have the same value.
解法一:递归遍历
class Solution:
def isSameTree(self, p, q):
if p and q:
return p.val == q.val \
and self.isSameTree(p.left, q.left) \
and self