Skip to content

Commit 6c2a4c2

Browse files
committed
add README
1 parent 24a864f commit 6c2a4c2

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

leetcode/topic/B-Tree/515/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## [515. Find Largest Value in Each Tree Row]((https://leetcode.com/problems/find-largest-value-in-each-tree-row/description/))
2+
3+
Given the root of a binary tree, return an array of the largest value in each
4+
row of the tree (0-indexed).
5+
6+
Ex1:
7+
![alt text](image.png)
8+
Input: root = [1,3,2,5,3,null,9]
9+
Output: [1,3,9]
10+
11+
Ex2:
12+
Input: root = [1,2,3]
13+
Output: [1,3]
14+
15+
### Approach
16+
17+
**Breadth-First Search (BFS)**
18+
- We can use BFS to traverse the tree level by level. We will use a queue to store
19+
the nodes at each level.
20+
- For each level, we will find the maximum value and add it to the result array.
21+
- We will repeat this process until we have traversed all levels of the tree.

leetcode/topic/B-Tree/515/image.png

55.3 KB
Loading

0 commit comments

Comments
 (0)