Flipping an Image
先左右翻转, 然后0/1互换
class Solution {
public int[][] flipAndInvertImage(int[][] A) {
rev(A);
inv(A);
return A;
}
private void inv(int[][] A) {
for(int i = 0 ; i < A.length; i++) {
for(int j = 0; j < A[0].length; j++) {
if(A[i][j] == 0)
A[i][j] = 1;
else
A[i][j] = 0;
}
}
}
private void rev(int[][] A) {
for(int k = 0; k < A.length; k++) {
swap(A, k);
}
}
private void swap(int[][]A, int k) {
int i = 0;
int j = A[0].length - 1;
while(i < j) {
int t = A[k][i];
A[k][i] = A[k][j];
A[k][j] = t;
i++;
j--;
}
}
}