JAVA | BFS and DFS ✅
Please Upvote \uD83D\uDE07\n---\n##### 1. DFS approach:\n\nclass Solution {\n    public boolean isSymmetric(TreeNode root) {\n        return help(root.left, roo
# Please Upvote \uD83D\uDE07\n---\n##### 1. DFS approach:\n```\nclass Solution {\n    public boolean isSymmetric(TreeNode root) {\n        return help(root.left, root.right);\n    }\n\n    private boolean help(TreeNode left, TreeNode right) {\n        if (left == null || right == null) {\n            return left == right;\n        }\n        if (left.val != right.val) {\n            return false;\n        }\n        boolean check1 = help(left.left, right.right);\n        boolean check2 = help(left.right, right.left);\n        return check1 && check2;\n    }\n}\n\n// TC: O(n), SC: O(n)\n```\n---\n##### 2. BFS approach:\n```\nclass Solution {\n    public boolean isSymmetric(TreeNode root) {\n        Queue<TreeNode> q = new LinkedList<>();\n        q.offer(root);\n\n        while (!q.isEmpty()) {\n            int n = q.size();\n            List<Integer> list = new ArrayList<>();\n\n            for (int i = 0; i < n; i++) {\n                TreeNode curr = q.poll();\n\n                if (curr == null) list.add(null);\n                else {\n                    list.add(curr.val);\n                    q.offer(curr.left);\n                    q.offer(curr.right);\n                }\n            }\n\n            if (!checkSymmetry(list)) return false;\n        }\n\n        return true;\n    }\n\n    public boolean checkSymmetry(List<Integer> list) {\n        int l = 0, r = list.size() - 1;\n\n        while (l < r) {\n            if (list.get(l++) != list.get(r--)) {\n                return false;\n            }\n        }\n\n        return true;\n    }\n}\n\n// TC: O(n), SC: O(n)\n```
['Tree', 'Depth-First Search', 'Breadth-First Search', 'Binary Tree', 'Java']