class Solution {
func maxDepth(_ root: TreeNode?) -> Int {
guard let root = root else {
return 0
}
var queue = [root]
var answer = 0
while !queue.isEmpty {
answer += 1
(0..<queue.count).forEach { _ in
let current = queue.removeFirst()
if let left = current.left {
queue.append(left)
}
if let right = current.right {
queue.append(right)
}
}
}
return answer
}
}