Class Solution
-
- All Implemented Interfaces:
public final class Solution
2923 - Find Champion I.
Easy
There are
n
teams numbered from0
ton - 1
in a tournament.Given a 0-indexed 2D boolean matrix
grid
of sizen * n
. For alli, j
that0 <= i, j <= n - 1
andi != j
teami
is stronger than teamj
ifgrid[i][j] == 1
, otherwise, teamj
is stronger than teami
.Team
a
will be the champion of the tournament if there is no teamb
that is stronger than teama
.Return the team that will be the champion of the tournament.
Example 1:
Input: grid = [0,1,0,0]
Output: 0
Explanation: There are two teams in this tournament.
grid1 == 1 means that team 0 is stronger than team 1. So team 0 will be the champion.
Example 2:
Input: grid = [0,0,1,1,0,1,0,0,0]
Output: 1
Explanation: There are three teams in this tournament.
grid0 == 1 means that team 1 is stronger than team 0.
grid2 == 1 means that team 1 is stronger than team 2.
So team 1 will be the champion.
Constraints:
n == grid.length
n == grid[i].length
2 <= n <= 100
grid[i][j]
is either0
or1
.For all
i grid[i][i]
is0.
For all
i, j
thati != j
,grid[i][j] != grid[j][i]
.The input is generated such that if team
a
is stronger than teamb
and teamb
is stronger than teamc
, then teama
is stronger than teamc
.
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final Integer
findChampion(Array<IntArray> grid)
-
-
Method Detail
-
findChampion
final Integer findChampion(Array<IntArray> grid)
-
-
-
-