package leetcode;

/**
 * https://leetcode.com/problems/score-after-flipping-matrix/
 */
public class Problem861 {
    public int matrixScore(int[][] A) {
        int nRow = A.length;
        int nCol = A.length > 0 ? A[0].length : 0;
        int[] score = score(A);
        for (int col = 0; col < nCol; col++) {
            String s = "";
            int[] newCol = new int[nRow];
            for (int row = 0; row < nRow; row++) {
                if (A[row][col] == 0) {

                } else {

                }
            }
        }
        for (int row = 0; row < nRow; row++) {
            String s = "";
            int[] newRow = new int[nCol];
            for (int col = 0; col < nCol; col++) {
                if (A[row][col] == 0) {
                    s += "1";
                    newRow[col] = 1;
                } else {
                    s += "0";
                    newRow[col] = 0;
                }
            }
            int val = Integer.parseInt(s, 2);
            if (val > score[row]) {
                score[row] = val;
                A[row] = newRow;
            }
        }
        int totalScore = 0;
        for (int s : score) {
            totalScore += s;
        }
        return totalScore;
    }

    private static int[] score(int[][] a) {
        int[] score = new int[a.length];
        for (int i = 0; i < a.length; i++) {
            String s = "";
            for (int j = 0; j < a[i].length; j++) {
                s += a[i][j];
            }
            score[i] = Integer.parseInt(s, 2);
        }
        return score;
    }

    public static void main(String[] args) {
        Problem861 prob = new Problem861();
//            {1, 1, 1, 1},
//            {1, 0, 0, 1},
//            {1, 1, 1, 1}
        System.out.println(prob.matrixScore(new int[][]{
            {0, 0, 1, 1},
            {1, 0, 1, 0},
            {1, 1, 0, 0}
        })); // 39
    }
}

@@ -264,128 +264,8 @@
 A);%0A
-        for (int col = 0; col %3C nCol; col++) %7B%0A            String s = %22%22;%0A            int%5B%5D newCol = new int%5BnRow%5D;%0A    
     
@@ -323,113 +323,8 @@
     
-    if (A%5Brow%5D%5Bcol%5D == 0) %7B%0A%0A                %7D else %7B%0A%0A                %7D%0A            %7D%0A        %7D%0A        
 for 
@@ -332,32 +332,32 @@
 int 
-row
+col
  = 0; 
-row
+col
  %3C n
-Row; row
+Col; col
 ++) 
@@ -374,496 +374,118 @@
     
-String s = %22%22;%0A            int%5B%5D newRow = new int%5BnCol%5D;%0A            for (int col = 0; col %3C nCol; col++) %7B%0A                if (A%5Brow%5D%5Bcol%5D == 0) %7B%0A                    s += %221%22;%0A                    newRow%5Bcol%5D = 1;%0A                %7D else %7B%0A                    s += %220%22;%0A                    newRow%5Bcol%5D = 0;%0A                %7D%0A            %7D%0A            int val = Integer.parseInt(s, 2);%0A            if (val %3E score%5Brow%5D
+%7D%0A        %7D%0A        for (int col = 0; col %3C nCol; col++) %7B%0A            for (int row = 0; row %3C nRow; row++
 ) %7B%0A
-                score%5Brow%5D = val;%0A                A%5Brow%5D = newRow;%0A
     
@@ -781,21 +781,17 @@
     
-Str
 in
-g
+t
  s = 
-%22%22
+0
 ;%0A  
@@ -868,16 +868,39 @@
  a%5Bi%5D%5Bj%5D
+ %3C%3C a%5Bi%5D.length - j - 1
 ;%0A      
@@ -934,30 +934,9 @@
 %5D = 
-Integer.parseInt(s, 2)
+s
 ;%0A  

Update problem 861