Easy Understand One pass Java Solution absolutely beat 100%
The idea is simple. For each row, use two pointers. One is going forward and the other is going backward. \n(1). If the two elements are the same, then make a s
The idea is simple. For each row, use two pointers. One is going forward and the other is going backward. \n(1). If the two elements are the same, then make a slight change like this 0 -> 1 or 1 -> 0. \n(2). If the two elements are different, DON\'T do anything. Just let it go.\n\nOnly scan the whole matrix once.\n\n```\nclass Solution {\n    public int[][] flipAndInvertImage(int[][] A) {\n        for (int i = 0; i < A.length; i++) {\n            int lo = 0, hi = A[0].length - 1;\n            while (lo <= hi) {\n                if (A[i][lo] == A[i][hi]) {\n                    A[i][lo] = 1 - A[i][lo];\n                    A[i][hi] = A[i][lo];\n                }\n                lo++;\n                hi--;\n            }\n        }\n        \n        return A;\n    }\n}\n````
[]