-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path861.txt
More file actions
50 lines (43 loc) · 1.05 KB
/
861.txt
File metadata and controls
50 lines (43 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class Solution {
public int matrixScore(int[][] A) {
for(int i=0;i<A.length;i++){
if(A[i][0]==0)flipr(A,i);
}
for(int c=1;c<A[0].length;c++){
int ones=0;
for(int r=0;r<A.length;r++){
ones+=A[r][c];
}
if(ones<A.length-ones){
flipc(A,c);
}
}
int res=0;
for(int i=0;i<A.length;i++){
int index=0;int b=0;
for(int j=A[0].length-1;j>=0;j--){
if(A[i][j]==1){
b=b|(1<<index);
}
index++;
}
res+=b;
}
return res;
}
public void flipr(int A[][],int r){
for(int i=0;i<A[0].length;i++){
if(A[r][i]==0)A[r][i]=1;
else A[r][i]=0;
}
}
public void flipc(int A[][],int c){
for(int i=0;i<A.length;i++){
if(A[i][c]==0)A[i][c]=1;
else A[i][c]=0;
}
}
}
//0011
//1010
//1100