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] =?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