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
相关推荐
CAE虚拟与现实3 分钟前
docker desktop中的build功能是要build什么
java·docker·容器
路径规划66617 分钟前
(MATLAB代码) 船舶轨迹聚类:K-means 算法(260912)
算法·matlab·kmeans
郝学胜-神的一滴2 小时前
Effective Python 条款 10 :海象运算符_=
开发语言·python·程序人生·开源
wuyk5552 小时前
Python零基础入门第十四章:异常处理(try-except)
开发语言·python
2601_962078192 小时前
Appium+Python+pytest自动化测试框架详解
自动化测试·python·appium·pytest·移动应用
allnlei2 小时前
s6-overlay - 装在 Docker 容器里的轻量级管家
java·docker·容器
卷无止境6 小时前
智能体开发环境ADE浅析,编程工具的下一次范式跃迁
后端·python
wzdark6 小时前
基于堆的优先队列实现原理与复杂度分析4
算法
彧azz8 小时前
图的存储结构详解:邻接矩阵的原理、实现与应用
开发语言·数据结构·学习·php
IT_Octopus8 小时前
IntelliJ 本地日志路径自定义:`-DLOG_PATH=./logs` 为什么总“不听话“
java·log4j·intellij-idea