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 totalScore = 0;
        int[] score = new int[nRow];
        for (int row = 0; row < nRow; row++) {
            int origScore = 0;
            int flipScore = 0;
            for (int col = 0; col < nCol; col++) {
                origScore += A[row][col] << nCol - col - 1;
                flipScore += (A[row][col] ^ 1) << nCol - col - 1;
            }
            score[row] = (origScore > flipScore) ? origScore : flipScore;
        }
        for (int col = 0; col < nCol; col++) {
            for (int row = 0; row < nRow; row++) {
            }
        }
        for (int s : score) {
            totalScore += s;
        }
        return totalScore;
    }

    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
    }
}

@@ -232,36 +232,8 @@
  0;%0A
-        int totalScore = 0;%0A
     
@@ -247,16 +247,17 @@
 %5B%5D score
+s
  = new i
@@ -583,16 +583,17 @@
    score
+s
 %5Brow%5D = 
@@ -643,32 +643,60 @@
 core;%0A        %7D%0A
+        int totalScore = 0;%0A
         for (int
@@ -742,71 +742,108 @@
     
-for (int row = 0; row %3C nRow; row++) %7B%0A            %7D%0A    
+int origScore = 0;%0A            int flipScore = 0;%0A            int%5B%5D flipScores = new int%5BnRow%5D;%0A
     
-%7D%0A
     
@@ -859,17 +859,34 @@
 int 
-s : score
+row = 0; row %3C nRow; row++
 ) %7B%0A
@@ -897,21 +897,24 @@
         
-total
+    orig
 Score +=
@@ -915,16 +915,26 @@
 ore += s
+cores%5Brow%5D
 ;%0A      
@@ -935,26 +935,24 @@
         
-%7D%0A
         
 return t
@@ -947,358 +947,324 @@
     
-return totalScore;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem861 prob = new Problem861();%0A//            %7B1, 1, 1, 1%7D,%0A//            %7B1, 0, 0, 1%7D,%0A//            %7B1, 1, 1, 1%7D%0A        System.out.println(prob.matrix
+int fs = scores%5Brow%5D %5E (1 %3C%3C nCol - col - 1);%0A                flipScore += fs;%0A                flipScores%5Brow%5D = fs;%0A            %7D%0A            if (orig
 Score
-(new int%5B%5D%5B%5D%7B%0A            %7B0, 0, 1, 1%7D,%0A            %7B1, 0, 1, 0%7D,%0A            %7B1, 1, 0, 0%7D%0A        %7D)); // 39
+ %3C flipScore) %7B%0A                scores = flipScores;%0A            %7D%0A            totalScore = Math.max(origScore, flipScore);%0A        %7D%0A        return totalScore;
 %0A   

Solve probelm 861