From 0498cf3935ead6fdf06495e00004ed8e6f2146e3 Mon Sep 17 00:00:00 2001 From: binglu18 <57309010+binglu18@users.noreply.github.com> Date: Fri, 20 Aug 2021 15:33:59 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E8=A1=A5=E5=85=850102.=E4=BA=8C=E5=8F=89?= =?UTF-8?q?=E6=A0=91=E7=9A=84=E5=B1=82=E5=BA=8F=E9=81=8D=E5=8E=86.md=20515?= =?UTF-8?q?=E9=A2=98java=E8=A7=A3=E6=B3=95=E4=BA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0102.二叉树的层序遍历.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/problems/0102.二叉树的层序遍历.md b/problems/0102.二叉树的层序遍历.md index 0f9b2df6..4a26d853 100644 --- a/problems/0102.二叉树的层序遍历.md +++ b/problems/0102.二叉树的层序遍历.md @@ -1070,6 +1070,29 @@ class Solution { return retVal; } } + +方法二:用一个max变量来保存最大值 +class Solution { + public List largestValues(TreeNode root) { + Queue queue = new LinkedList(); + List result = new ArrayList<>(); + if (root!=null) queue.add(root); + while(!queue.isEmpty()){ + int size = queue.size(); + int max = Integer.MIN_VALUE; // 初始化为最小值 + for(int i=0;i Date: Fri, 20 Aug 2021 15:37:35 +0800 Subject: [PATCH 2/3] =?UTF-8?q?update=20=E6=96=B9=E6=B3=95=E4=BA=8C=200102?= =?UTF-8?q?.=E4=BA=8C=E5=8F=89=E6=A0=91=E7=9A=84=E5=B1=82=E5=BA=8F?= =?UTF-8?q?=E9=81=8D=E5=8E=86.md=20515=E9=A2=98java=20format?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0102.二叉树的层序遍历.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/problems/0102.二叉树的层序遍历.md b/problems/0102.二叉树的层序遍历.md index 4a26d853..15d00af2 100644 --- a/problems/0102.二叉树的层序遍历.md +++ b/problems/0102.二叉树的层序遍历.md @@ -1070,8 +1070,10 @@ class Solution { return retVal; } } +``` -方法二:用一个max变量来保存最大值 +```java +//方法二:用一个max变量来保存最大值 class Solution { public List largestValues(TreeNode root) { Queue queue = new LinkedList(); From 07d27158b238812f603f250794b9a681f71e7f8e Mon Sep 17 00:00:00 2001 From: binglu18 <57309010+binglu18@users.noreply.github.com> Date: Fri, 20 Aug 2021 16:10:24 +0800 Subject: [PATCH 3/3] =?UTF-8?q?update=200102.=E4=BA=8C=E5=8F=89=E6=A0=91?= =?UTF-8?q?=E7=9A=84=E5=B1=82=E5=BA=8F=E9=81=8D=E5=8E=86.md=20515java?= =?UTF-8?q?=E8=A7=A3=E6=B3=95=E4=BA=8Cformat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0102.二叉树的层序遍历.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/problems/0102.二叉树的层序遍历.md b/problems/0102.二叉树的层序遍历.md index 15d00af2..d0f584fe 100644 --- a/problems/0102.二叉树的层序遍历.md +++ b/problems/0102.二叉树的层序遍历.md @@ -1078,16 +1078,17 @@ class Solution { public List largestValues(TreeNode root) { Queue queue = new LinkedList(); List result = new ArrayList<>(); - if (root!=null) queue.add(root); + if (root != null) queue.add(root); + while(!queue.isEmpty()){ int size = queue.size(); int max = Integer.MIN_VALUE; // 初始化为最小值 - for(int i=0;i