python-algorithm
leetcode 2643. Row With Maximum Ones
무적김두칠
2024. 1. 2. 20:26
https://leetcode.com/problems/row-with-maximum-ones/description/
Row With Maximum Ones - LeetCode
Can you solve this real interview question? Row With Maximum Ones - Given a m x n binary matrix mat, find the 0-indexed position of the row that contains the maximum count of ones, and the number of ones in that row. In case there are multiple rows that ha
leetcode.com
1 2 3 4 5 6 7 8 9 10 11 | class Solution: def rowAndMaximumOnes(self, mat: List[List[int]]) -> List[int]: start_sum, idx = sum(mat[0]), 0 for i in range(1, len(mat)): if sum(mat[i]) > start_sum: idx = i start_sum = sum(mat[i]) answer = [idx, start_sum] return answer | cs |
반응형