2643. Row With Maximum Ones Easy
1/**
2 * [2643] Row With Maximum Ones
3 *
4 * 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.
5 * In case there are multiple rows that have the maximum count of ones, the row with the smallest row number should be selected.
6 * Return an array containing the index of the row, and the number of ones in it.
7 *
8 * <strong class="example">Example 1:
9 *
10 * Input: mat = [[0,1],[1,0]]
11 * Output: [0,1]
12 * 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].
13 *
14 * <strong class="example">Example 2:
15 *
16 * Input: mat = [[0,0,0],[0,1,1]]
17 * Output: [1,2]
18 * 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].
19 *
20 * <strong class="example">Example 3:
21 *
22 * Input: mat = [[0,0],[1,1],[0,0]]
23 * Output: [1,2]
24 * Explanation: The row indexed 1 has the maximum count of ones (2). So the answer is [1,2].
25 *
26 *
27 * Constraints:
28 *
29 * m == mat.length
30 * n == mat[i].length
31 * 1 <= m, n <= 100
32 * mat[i][j] is either 0 or 1.
33 *
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/row-with-maximum-ones/
38// discuss: https://leetcode.com/problems/row-with-maximum-ones/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43 pub fn row_and_maximum_ones(mat: Vec<Vec<i32>>) -> Vec<i32> {
44 vec![]
45 }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52 use super::*;
53
54 #[test]
55 fn test_2643() {
56 }
57}
58
Back
© 2025 bowen.ge All Rights Reserved.