leetcode100 Same Tree java
2017-03-21 16:44
369 查看
欢迎转载,转载请注明原地址:
http://blog.csdn.net/u013190088/article/details/64444050
Two binary trees are considered equal if they are structurally identical and the nodes have the same value.
如果不用递归,用两个栈也可以解决。
http://blog.csdn.net/u013190088/article/details/64444050
Description
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.
解法
用递归,考虑好结束条件即可。public boolean isSameTree(TreeNode p, TreeNode q) { if(p == null && q == null) return true; if(p ==null || q == null) return false; if(p.val == q.val) return isSameTree(p.left, q.left) && isSameTree(p.right, q.right); return false; }
如果不用递归,用两个栈也可以解决。
相关文章推荐
- leetcode100题< Same Tree >(java)
- LeetCode100——Same Tree
- [LeetCode]: 100: Same Tree
- 【一天一道LeetCode】#100. Same Tree(100题大关)
- 【LeetCode从零单排】No100 Same Tree && No101 Symmetric Tree
- LeetCode Same Tree 100
- Leetcode 100 : same Tree
- leetcode:SameTree java python
- Leetcode-100: Same Tree
- leetcode 100 —— Same Tree
- <LeetCode OJ> Same Tree【100】
- (java)leetcode Same Tree
- leetcode_c++:树: Same Tree(100)
- Same Tree leetcode java
- 【LeetCode】(100)Same Tree(Easy)
- leetcode:100 Same Tree-每日编程第六题
- LeetCode 100:Same Tree
- LeetCode@Tree_100_Same_Tree
- leetcode解题之100# Same Tree Java版
- 【一天一道LeetCode】#100. Same Tree(100题大关)