Symmetric Tree
Page 1 of 1
Symmetric Tree
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;
}
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;
}
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|