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
相关推荐
hi星尘25 分钟前
深度解析:基于Python的微信小程序自动化操作实现
python·微信小程序·自动化
xin007hoyo1 小时前
算法笔记.染色法判断二分图
数据结构·笔记·算法
Doker 多克1 小时前
Django 缓存框架
python·缓存·django
此木|西贝2 小时前
【设计模式】享元模式
java·设计模式·享元模式
miracletiger3 小时前
uv 新的包管理工具总结
linux·人工智能·python
我不会编程5553 小时前
Python Cookbook-6.10 保留对被绑定方法的引用且支持垃圾回收
开发语言·python
ʚɞ 短腿欧尼3 小时前
关系数据的可视化
python·pycharm·可视化·数据可视化·图表
এ᭄画画的北北3 小时前
力扣-234.回文链表
算法·leetcode·链表
李少兄3 小时前
解决Spring Boot多模块自动配置失效问题
java·spring boot·后端