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]
'LeetCode > Top Interview Q. - Easy' 카테고리의 다른 글
LeetCode. Convert Sorted Array to Binary Search Tree [Trees] (0) | 2020.06.07 |
---|---|
LeetCode. Binary Tree Level Order Traversal [Trees] (0) | 2020.06.07 |
LeetCode. Validate Binary Search Tree [Trees] (0) | 2020.06.06 |
LeetCode. Maximum Depth of Binary Tree [Trees] (0) | 2020.06.05 |
LeetCode. Linked List Cycle [Linked List] (0) | 2020.06.04 |
댓글