LeetCode. Symmetric Tree [Trees]
Problem:
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).
For example, this binary tree [1,2,2,3,4,4,3] is symmetric:
But the following [1,2,2,null,3,null,3] is not:
-Summary-
1. If a tree has no root or root itself exist, it will always return True
2. Otherwise, we keep check below condition recursively of the Tree's left and right subtree
- leftSub.left == rightSub.right
- leftSub.right == rightSub.left
discussion을 보니 아래와 같이 iterative 하게 푸는 방법도 있었다.
leetcode.com/problems/symmetric-tree/discuss/33057/Python-iterative-way-using-a-queue
Python iterative way using a queue - LeetCode Discuss
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
모든 문제에 대한 저작권은 LeetCode 회사에 있습니다. [Copyright © 2020 LeetCode]