Skip to content

Commit 847edaf

Browse files
committed
Update 515. 在每个树行中找最大值
1 parent 25f129b commit 847edaf

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

algorithms/find-largest-value-in-each-tree-row.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ var largestValues = function (root) {
2020

2121
while (queue.length > 0) {
2222
let size = queue.length;
23-
let max = null;
23+
let max = queue[0].val;
2424
// 通过size实现按层处理
2525
while (size--) {
2626
const node = queue.shift();
27-
// 找到每层的最大值
28-
if (max == null || node.val > max) {
27+
// update max
28+
if (node.val > max) {
2929
max = node.val;
3030
}
3131
node.left && queue.push(node.left);

0 commit comments

Comments
 (0)