105.找到冠军
方法一
class Solution {
public int findChampion(int[][] grid) {
int j=0;
for(int i=1;i<grid.length;i++){
if(grid[j][i]==0)
j=i;
}
return j;
}
}
class Solution(object):
def findChampion(self, grid):
j=0
for i in range(len(grid)):
if grid[j][i]==0:
j=i
return j
方法二
class Solution {
public int findChampion(int[][] grid) {
int count=0;
for(int i=0;i<grid.length;i++){
count=0;
for(int j=0;j<grid[0].length;j++){
if(grid[i][j]==1){
count++;
}
}
if(count==grid.length-1){
return i;
}
}
return 0;
}
}
class Solution(object):
def findChampion(self, grid):
count=0
for i in range(len(grid)):
count=0
for j in range(len(grid[0])):
if grid[i][j]==1:
count+=1
if count==len(grid)-1:
return i
return 0