From 2e81b18c5d92d99e7b50c35f0db76f8b824b3915 Mon Sep 17 00:00:00 2001 From: jianghongcheng <35664721+jianghongcheng@users.noreply.github.com> Date: Mon, 22 May 2023 19:04:11 -0500 Subject: [PATCH] =?UTF-8?q?Update=200257.=E4=BA=8C=E5=8F=89=E6=A0=91?= =?UTF-8?q?=E7=9A=84=E6=89=80=E6=9C=89=E8=B7=AF=E5=BE=84.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0257.二叉树的所有路径.md | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/problems/0257.二叉树的所有路径.md b/problems/0257.二叉树的所有路径.md index 31cbdb56..7bd56fbd 100644 --- a/problems/0257.二叉树的所有路径.md +++ b/problems/0257.二叉树的所有路径.md @@ -470,7 +470,7 @@ class Solution { ## Python: -递归法+回溯(版本一) +递归法+回溯 ```Python # Definition for a binary tree node. class Solution: @@ -561,16 +561,11 @@ class Solution: 迭代法: ```Python -from collections import deque - - class Solution: - """二叉树的所有路径 迭代法""" def binaryTreePaths(self, root: TreeNode) -> List[str]: # 题目中节点数至少为1 - stack, path_st, result = deque([root]), deque(), [] - path_st.append(str(root.val)) + stack, path_st, result = [root], [str(root.val)], [] while stack: cur = stack.pop()