1. 程式人生 > >100. Same Tree (Tree)

100. Same Tree (Tree)

left else nbsp node public 不能 單獨 iss pub

註意null的時候要單獨判斷 因為不能用val

 1 class Solution {
 2     public boolean isSameTree(TreeNode p, TreeNode q) {
 3         if(p == null && q == null) {
 4             return true;
 5         }else if (p== null && q != null) {
 6             return false;
 7         }else if(p != null && q == null
) { 8 return false; 9 } 10 if(p.val != q.val) { 11 return false; 12 }else { 13 return(isSameTree(p.left, q.left) && isSameTree(p.right, q.right)); 14 } 15 16 } 17 }

100. Same Tree (Tree)