Skip to content

Commit 88af081

Browse files
authored
Create 1975. Maximum Matrix Sum (#642)
2 parents 5f3c48e + be1a029 commit 88af081

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

1975. Maximum Matrix Sum

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public:
3+
long long maxMatrixSum(vector<vector<int>>& matrix) {
4+
long long ans = 0;
5+
int min_num = INT_MAX;
6+
int neg = 0;
7+
8+
for(auto i : matrix) {
9+
for(int j : i) {
10+
if(j < 0) neg++;
11+
min_num = min(min_num, abs(j));
12+
ans += abs(j);
13+
}
14+
}
15+
16+
if(neg%2==0) return ans;
17+
else return ans-2*min_num;
18+
}
19+
};

0 commit comments

Comments
 (0)