105.找到冠军

方法一

java 复制代码
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;
    }
}
python 复制代码
class Solution(object):
    def findChampion(self, grid):
        j=0
        for i in range(len(grid)):
            if grid[j][i]==0:
                j=i
        return j

方法二

java 复制代码
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;
    }
}
python 复制代码
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
相关推荐
圣保罗的大教堂28 分钟前
leetcode 3418. 机器人可以获得的最大金币数 中等
leetcode
WiChP38 分钟前
【V0.1B5】从零开始的2D游戏引擎开发之路
java·服务器·数据库
cch891844 分钟前
汇编与Java:底层与高层的编程对决
java·开发语言·汇编
荒川之神2 小时前
拉链表概念与基本设计
java·开发语言·数据库
cch89182 小时前
汇编与Go:底层到高层的编程差异
java·汇编·golang
workflower2 小时前
用硬件换时间”与“用算法降成本”之间的博弈
人工智能·算法·安全·集成测试·无人机·ai编程
chushiyunen2 小时前
python中的@Property和@Setter
java·开发语言·python