diff --git a/animation-simulation/二叉树/二叉树基础.md b/animation-simulation/二叉树/二叉树基础.md index 17fca26..01a6f2c 100644 --- a/animation-simulation/二叉树/二叉树基础.md +++ b/animation-simulation/二叉树/二叉树基础.md @@ -406,6 +406,42 @@ public: }; ``` +Swift Code: + +```swift +class Solution { + func levelOrder(_ root: TreeNode?) -> [[Int]] { + var res:[[Int]] = [] + guard root != nil else { + return res + } + var queue:[TreeNode?] = [] + queue.append(root!) + + while !queue.isEmpty { + let size = queue.count + var list:[Int] = [] + + for i in 0..