Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4bda99c

Browse files
authored
Create Find Champion I.java
1 parent 0878cdc commit 4bda99c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Easy/Find Champion I.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import java.util.Map.Entry;
2+
3+
class Solution {
4+
public int findChampion(int[][] grid) {
5+
Map<Integer, Integer> map = new HashMap<>();
6+
for (int i = 0; i < grid.length; i++) {
7+
for (int j = 0; j < grid[0].length; j++) {
8+
if (grid[i][j] == 1) {
9+
map.put(i, map.getOrDefault(i, 0) + 1);
10+
}
11+
}
12+
}
13+
return map.entrySet()
14+
.stream()
15+
.filter(entry -> entry.getValue() == grid.length - 1)
16+
.findFirst()
17+
.map(Entry::getKey)
18+
.orElse(-1);
19+
}
20+
}

0 commit comments

Comments
 (0)