Same Tree LeetCode
2014-08-13 11:05
239 查看
https://oj.leetcode.com/problems/same-tree/
public boolean isSameTree(TreeNode p, TreeNode q) { if(p==null&&q==null){ return true; } if(p==null){ return false; } if(q==null){ return false; } Stack<TreeNode> stackA= new Stack<TreeNode>(); Stack<TreeNode> stackB= new Stack<TreeNode>(); stackA.push(p); stackB.push(q); while(!stackA.empty()&&!stackB.empty()){ TreeNode a= stackA.pop(); TreeNode b= stackB.pop(); if(a.val!=b.val){ return false; } if(a.left!=null){ if(b.left==null){ return false; } stackA.push(a.left); stackB.push(b.left); }else{ if(b.left!=null){ return false; } } if(a.right!=null){ if(b.right==null){ return false; } stackA.push(a.right); stackB.push(b.right); }else{ if(b.right!=null){ return false; } } } return true; }
相关文章推荐
- leetcode Same Tree
- LeetCode之Same Tree
- leetcode--Same Tree
- LeetCode——same-tree
- LeetCode之Same Tree
- Leetcode: Same Tree 理解分析
- Leetcode Same Tree
- 100. Same Tree Leetcode Python
- Leetcode 100 : same Tree
- LeetCode:Same Tree
- leetcode Same Tree
- Leetcode Same Tree
- [LeetCode]Same Tree
- LeetCode Same Tree
- leetcode -- Same Tree -- 简单重点
- Leetcode: Same Tree
- LeetCode Same Tree
- LeetCode Same Tree OJ 算法 刷题
- LeetCode Same Tree
- LeetCode OJ Same Tree