<commit_before>/**
 * Definition for binary tree
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
public class Solution {
    public boolean isSymmetricRecursive(TreeNode root) {
        if (root == null) {
            return true;
        }
        return this.check(root.left, root.right);
    }
    
    public boolean check(TreeNode left, TreeNode right) {
        if (left == null && right == null) {
            return true;
        }
        if ((left == null && right != null) || (left != null && right == null) || (left.val != right.val)) {
            return false;
        }
        return this.check(left.left, right.right) && this.check(left.right, right.left);
    }

    public boolean isSymmetricIterative(TreeNode root) {
        if (root == null) {
            return true;
        }
        Stack<TreeNode> left = new Stack<TreeNode>();
        Stack<TreeNode> right = new Stack<TreeNode>();
        TreeNode leftRoot = root.left;
        TreeNode rightRoot = root.right;
        while (left.isEmpty() == false || leftRoot != null) {
            if (leftRoot != null) {
                if (rightRoot == null) {
                    return false;
                }
                left.push(leftRoot);
                right.push(rightRoot);
                leftRoot = leftRoot.left;
                rightRoot = rightRoot.right;
            } else {
                if (right.isEmpty() == true || rightRoot != null) {
                    return false;
                }
                TreeNode currLeft = left.pop();
                TreeNode currRight = right.pop();
                if (currLeft.val != currRight.val) {
                    return false;
                }
                leftRoot = currLeft.right;
                rightRoot = currRight.left;
            }
        }
        return right.isEmpty() && rightRoot == null;
    }
}
}<commit_msg>SymmetricTree<commit_after>/**
 * Definition for binary tree
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
public class RecursiveSolution {
    public boolean isSymmetricRecursive(TreeNode root) {
        if (root == null) {
            return true;
        }
        return this.check(root.left, root.right);
    }
    
    public boolean check(TreeNode left, TreeNode right) {
        if (left == null && right == null) {
            return true;
        }
        if ((left == null && right != null) || (left != null && right == null) || (left.val != right.val)) {
            return false;
        }
        return this.check(left.left, right.right) && this.check(left.right, right.left);
    }
}

public class IterativeSolution {
    public boolean isSymmetric(TreeNode root) {
        if (root == null) {
            return true;
        }
        
        Stack<TreeNode> left = new Stack<TreeNode>();
        Stack<TreeNode> right = new Stack<TreeNode>();
        TreeNode leftRoot = root.left;
        TreeNode rightRoot = root.right;
        while (left.isEmpty() == false || leftRoot != null) {
            if (leftRoot != null) {
                if (rightRoot == null) {
                    return false;
                }
                
                left.push(leftRoot);
                right.push(rightRoot);
                leftRoot = leftRoot.left;
                rightRoot = rightRoot.right;
            } else {
                if (right.isEmpty() || rightRoot != null) {
                    return false;
                }
                
                TreeNode currLeft = left.pop();
                TreeNode currRight = right.pop();
                if (currLeft.val != currRight.val) {
                    return false;
                }
                
                leftRoot = currLeft.right;
                rightRoot = currRight.left;
            }
        }
        
        return right.isEmpty() && rightRoot == null;
    }
}
{'fraction_non_alphanumeric': 0.11496259351620948, 'fraction_numerical': 0.0, 'mean_word_length': 1.4104567307692308, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5413086', 'n_tokens_mistral': 1089, 'n_tokens_neox': 1060, 'n_words': 268}