严氏北美IT公司面试真题汇总和解答论坛
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Symmetric Tree

Go down

Symmetric Tree Empty Symmetric Tree

Post by Admin Sat Oct 21, 2017 4:17 pm

public static boolean recurse(BTreeNode root) {
if (root == null)
return true;
return recurse(root.left, root.right);
}

public static boolean recurse(BTreeNode left, BTreeNode right) {
if (left == null && right == null)
return true;
else if (right == null || left == null)
return false;


if (left.val != right.val)
return false;

if (!recurse(left.left, right.right))
return false;
if (!recurse(left.right, right.left))
return false;

return true;
}

Admin
Admin

Posts : 124
Join date : 2017-10-21

https://csinterviewquestions.forumotion.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum