Quoted By:
>import java.util.Stack;
>class Solution {
> public boolean isSymmetric(TreeNode root) {
> TreeNode leftNode, rightNode;
> Stack<TreeNode> unexploredLefts = new Stack<>();
> Stack<TreeNode> unexploredRights = new Stack<>();
> unexploredLefts.push(root.left);
> unexploredRights.push(root.right);
> while(!unexploredLefts.empty() && !unexploredRights.empty()){
> leftNode = unexploredLefts.pop();
> rightNode = unexploredRights.pop();
> if(leftNode.val != rightNode.val){
> return false;
> }
> //Outer nodes
> if(leftNode.left==null && rightNode.right==null){
> //nothing needs to be done
> } else if (leftNode.left!=null && rightNode.right!=null){
> unexploredLefts.push(leftNode.left);
> unexploredRights.push(rightNode.right);
> } else {
> //Only happens if the outer children are different
> return false;
> }
> //Inner nodes
> if(leftNode.right==null && rightNode.left==null){
> //nothing needs to be done
> } else if (leftNode.right!=null && rightNode.left!=null){
> unexploredLefts.push(leftNode.right);
> unexploredRights.push(rightNode.left);
> } else {
> //Only happens if the outer children are different
> return false;
> }
> }
> return true;
> }
>}
Terrible 16th percentile solution. Is it due to using Java?