Symmetric Tree

Leetcode considers this question to be easy, but it was a bit more complicated than that at first for me. Letโ€™s try solving it three different ways: Whenever I can, I always try to do BFS. It seems much more natural. BFS - 1st solution func isSymmetricBFS(_ root: TreeNode?) -> Bool { var queue: [TreeNode?] = [] queue.append(root) while !queue.isEmpty { let temp = queue queue.removeAll() // ๐Ÿ”‘ to make sure you don't expand on `nil` nodesย โ€”ย otherwise it would be endless for node in temp where node !...

January 12, 2025 ยท 2 min