We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5f3c48e commit be1a029Copy full SHA for be1a029
1975. Maximum Matrix Sum
@@ -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