From 9116bc63ce0677d71a6e6580053bab5bb94cb9c3 Mon Sep 17 00:00:00 2001 From: frank-tian Date: Mon, 19 Jul 2021 23:13:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20Swift=20=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- animation-simulation/二叉树/二叉树基础.md | 36 +++++++++++++++++++++++ 1 file changed, 36 insertions(+) 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..