1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| class Solution { public int[] rowAndMaximumOnes(int[][] mat) { int m = mat.length, n = mat[0].length;
int rowIndex = m - 1, maxCount = 0; for (int i = m - 1; i >= 0; i--) { int count = 0; for (int j = 0; j < n; j++) { count += mat[i][j]; } if (count >= maxCount) { maxCount = count; rowIndex = i; } }
return new int[]{rowIndex, maxCount}; } }
|
References
2643. Row With Maximum Ones