Leetcode:1252. 奇數值單元格的數目

class Solution:
    def oddCells(self, n: int, m: int, indices: List[List[int]]) -> int:
        rows=[0]*n
        cols=[0]*m
        for x,y in indices:
            rows[x]+=1#使用Python的這種語法可以直接按照題意來模擬
            cols[y]+=1
        sum=0
        for i in range(n):
            for j in range(m):
                if (rows[i]+cols[j])%2==1:
                    sum+=1;
        return sum
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章