#2643

Row With Maximum Ones

newbie · 240 · lc easy +18 · verified · 74.3% accepted · 595 likes · top 85%

Description

Given an m x n binary matrix mat, find the row with the most 1s. Break ties by choosing the row with the smaller index. Return [row_index, count_of_ones].

Example 1:

Input: mat = [[0,1],[1,0]]
Output: [0,1]
Explanation: Both rows have the same number of 1's. So we return the index of the smaller row, 0, and the maximum count of ones (1). So, the answer is [0,1].

Example 2:

Input: mat = [[0,0,0],[0,1,1]]
Output: [1,2]
Explanation: The row indexed 1 has the maximum count of ones (2). So we return its index, 1, and the count. So, the answer is [1,2].

Example 3:

Input: mat = [[0,0],[1,1],[0,0]]
Output: [1,2]
Explanation: The row indexed 1 has the maximum count of ones (2). So the answer is [1,2].

Code

1
2
3