MCPcopy Create free account
hub / github.com/codedecks-in/LeetCode-Solutions / checkMirror

Method checkMirror

Java/symmetric-tree.java:19–33  ·  view source on GitHub ↗
(TreeNode lt, TreeNode rt)

Source from the content-addressed store, hash-verified

17 return checkMirror(root.left, root.right);
18 }
19 public boolean checkMirror(TreeNode lt, TreeNode rt){
20 /* if root's left and root's right both are null, is then that subtree is symmetric */
21 if(lt==null && rt==null)
22 return true;
23
24 /* if root's left is null and root's right is not null and vice-versa, is then that subtree is not symmetric */
25 if((lt!=null && rt==null) || (lt==null && rt!=null))
26 return false;
27
28 /* check if left node's value matches with right node's value, and recursively check for their left and right subtrees */
29 if(lt.val==rt.val && checkMirror(lt.left,rt.right) && checkMirror(lt.right,rt.left))
30 return true;
31
32 return false;
33 }
34}

Callers 1

isSymmetricMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected