/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ public class Solution { public boolean isSameTree(TreeNode p, TreeNode q) { if(p == null && q == null){ return true; } if(p == null || q != null){ return false; } if(p != null || q == null){ return false; } if(p.val == q.val){ return (isSameTree(p.left, q.left)) && isSameTree(p.right, q.right); } else { return false; } } }
相关文章
- 12-13[LeetCode] 1376. Time Needed to Inform All Employees
- 12-13LeetCode每日一题——690. 员工的重要性
- 12-13第一次leetcode周赛总结
- 12-13CF161D Distance in Tree(点分治)
- 12-13LeetCode(7) - Reverse Integer
- 12-13【URAL1018】Binary Apple Tree
- 12-13[Leetcode]19.把数组排成最小的数
- 12-13LeetCode --- 字符串系列 --- 转换成小写字母
- 12-13leetcode283. 移动零
- 12-13LeetCode——179. 最大数