515-在每个树行中找最大值

力扣515

https://leetcode-cn.com/problems/find-largest-value-in-each-tree-row/

也就是找每行的最大值

思路一:bfs层次遍历每行嘛,找最大值并加入res

Java二叉树的层次遍历

1. 层次遍历和BFS

之前写过二叉树的前中后序遍历,不懂的点这里,今天介绍的是层次遍历,层次遍历概念很简单,我直接盗用力扣上面的图了,采用BFS也是显而易见的

对比图

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×