From 0c77206ecae5acece7cc12572ed08682b3147c20 Mon Sep 17 00:00:00 2001 From: Zeeland Date: Thu, 5 Jan 2023 22:01:19 +0800 Subject: [PATCH] =?UTF-8?q?update:=20=200104.=E4=BA=8C=E5=8F=89=E6=A0=91?= =?UTF-8?q?=E7=9A=84=E6=9C=80=E5=A4=A7=E6=B7=B1=E5=BA=A6:=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96python=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0102.二叉树的层序遍历.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/problems/0102.二叉树的层序遍历.md b/problems/0102.二叉树的层序遍历.md index 406242a7..3b68592f 100644 --- a/problems/0102.二叉树的层序遍历.md +++ b/problems/0102.二叉树的层序遍历.md @@ -2532,20 +2532,18 @@ class Solution: return 0 queue_ = [root] - result = [] + depth = 0 while queue_: length = len(queue_) - sub = [] for i in range(length): cur = queue_.pop(0) sub.append(cur.val) #子节点入队列 if cur.left: queue_.append(cur.left) if cur.right: queue_.append(cur.right) - result.append(sub) + depth += 1 - - return len(result) + return depth ``` Go: