Wrong test Cases for node value


#1

All the test cases is not checking the value of the node. The tree is not symmetric if the value at the node is different.
Your all test cases will be passed from the following code without checking the value of the node

public class Solution {
public int isSymmetric(TreeNode A) {
Queue q=new LinkedList();
try{
q.add(A.left);
q.add(A.right);
while(!q.isEmpty()){
TreeNode l=q.remove();
TreeNode r=q.remove();
if(l==null && r==null){
continue;
}
q.add(l.left);
q.add(r.right);
q.add(l.right);
q.add(r.left);
}
}
catch(Exception e){
return 0;
}
return 1;
}
}

while it is not the correct code. The correct code would be the which also check the value of the node

class Solution {
public boolean isSymmetric(TreeNode A) {
Queue q=new LinkedList();
if(A==null){
return true;
}
try{
q.add(A.left);
q.add(A.right);
while(!q.isEmpty()){
TreeNode l=q.poll();
TreeNode r=q.poll();
if(l==null && r==null){
continue;
}
if(l.val!=r.val){
return 0;
}
q.add(l.left);
q.add(r.right);
q.add(l.right);
q.add(r.left);
}
}
catch(Exception e){
return 0;
}
return 1;
}
}