Open liuyingbin19222 opened 4 years ago
var isSameTree = (p,q) => { if(p == null && q == null ) return true; if( p == null || q == null) return false; if(p.val != q.val) return false; return isSameTree(p.left , q.left) && isSameTree(p.right , q.right); }
迭代实现:
while(p.left != null){ if( p.val != q.val && p != null && q != null){ return false; } p = p.left == null ? p.left : p.right; q = q.left == null ? q.right : q.right; } return true;
迭代实现: