Leetcode#2923. Find Champion I
Problem
There are n
teams numbered from 0
to n - 1
in a tournament.
Given a 0-indexed 2D boolean matrix grid
of size n * n
. For all i, j
that 0 <= i, j <= n - 1
and i != j
team i
is stronger than team j
if grid[i][j] == 1
, otherwise, team j
is stronger than team i
.
Team a
will be the champion of the tournament if there is no team b
that is stronger than team a
.
Return the team that will be the champion of the tournament.
Example 1:
1 | Input: grid = [[0,1],[0,0]] |
Example 2:
1 | Input: grid = [[0,0,1],[1,0,1],[0,0,0]] |
Constraints:
n == grid.length
n == grid[i].length
2 <= n <= 100
grid[i][j]
is either0
or1
.- 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
.
Solve
單純看哪一隊強過所有其他隊伍
1 | class Solution: |
本部落格所有文章除特別聲明外,均採用 CC BY-NC-SA 4.0 許可協議。轉載請註明來自 Imisky!
評論