Skip to content

Commit c1a7ecc

Browse files
authored
Create row-with-maximum-ones.cpp
1 parent f18b189 commit c1a7ecc

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

C++/row-with-maximum-ones.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Time: O(m * n)
2+
// Space: O(1)
3+
4+
// array
5+
class Solution {
6+
public:
7+
vector<int> rowAndMaximumOnes(vector<vector<int>>& mat) {
8+
vector<int> result = {-1, -1};
9+
for (int i = 0; i < size(mat); ++i) {
10+
const int curr = accumulate(cbegin(mat[i]), cend(mat[i]), 0);
11+
if (curr > result[1]) {
12+
result = {i, curr};
13+
}
14+
}
15+
return result;
16+
}
17+
};

0 commit comments

Comments
 (0)