Halo World

[LeetCode] 101. Symmetric Tree 본문

스터디/알고리즘 문제풀이

[LeetCode] 101. Symmetric Tree

_Yeony 2021. 10. 4. 10:20

https://leetcode.com/problems/symmetric-tree/

class Solution {
    public boolean isSymmetric(TreeNode root) {
        return isMirror(root.right, root.left);
    }
    
    private boolean isMirror(TreeNode n1, TreeNode n2){
        if(n1==null || n2==null) return n1==n2;
        return (n1.val == n2.val && isMirror(n1.left, n2.right) && isMirror(n1.right, n2.left));
    }
}