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
相关推荐
尽兴-14 小时前
Elasticsearch 生产集群最佳实践:模板治理、ILM 生命周期与运维体系
java·运维·elasticsearch·容量规划·ccs·分片设计
大数据新鸟14 小时前
Java 泛型(Generic)完整使用指南
java·windows·python
狼与自由14 小时前
AQS介绍
java·开发语言
早已忘记15 小时前
CI相关项
java·前端·ci/cd
Ulyanov16 小时前
构建企业级雷达电子战仿真引擎的工程化基础 第一篇:CI/CD流水线与自动化测试体系
python·ci/cd·架构·系统仿真·雷达电子战仿真
砍材农夫16 小时前
使用jstack排查死锁,面试考点
java
0xDevNull1 天前
Java反射机制深度解析:从原理到实战
java·开发语言·后端
华科易迅1 天前
MybatisPlus增删改查操作
android·java·数据库
standovon1 天前
Spring Boot整合Redisson的两种方式
java·spring boot·后端