-
Notifications
You must be signed in to change notification settings - Fork 0
/
Find Champion I
43 lines (34 loc) · 1.17 KB
/
Find Champion I
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class Solution:
def findChampion(self, grid: List[List[int]]) -> int:
n = len(grid)
a = 0
b = 0
ch = dict()
for i in range(n):
for j in range(n):
if i!=j:
if grid[i][j] == 1:
if i not in ch:
ch[i] =1
else:
ch[i]+=1
m = max(ch.values())
for k,v in ch.items():
if v == m:
return k
------------------------------------------------------------------------------------------------------------------------------
class Solution:
def findChampion(self, grid: List[List[int]]) -> int:
n = len(grid)
for i in range(n):
if sum(grid[i]) == n - 1:
return i
-----------------------------------------------------------------------------
class Solution:
def findChampion(self, grid: List[List[int]]) -> int:
for c in range(len(grid)):
for r in range(len(grid)):
if grid[r][c]:
break
else:
return c