标签:
题目:
Given two binary trees, write a function to check if they are equal or not.
Two binary trees are considered equal if they are structurally identical and the nodes have the same value.
思路:和symmetric tree非常类似的递归解法
1 public boolean isSameTree(TreeNode p, TreeNode q) 2 { 3 if(p==null&&q==null) return true; 4 if(p==null||q==null) return false; 5 return (p.val == q.val) && isSameTree(p.left, q.left) && isSameTree(p.right, q.right); 6 7 }
标签:
原文地址:http://www.cnblogs.com/hygeia/p/4695070.html