1. Description:
Notes:
2. Examples:
3.Solutions:
1 /** 2 * Created by sheepcore on 2019-02-24 3 */ 4 class Solution { 5 public int[][] flipAndInvertImage(int[][] A) { 6 for (int i = 0; i < A.length; i++) 7 for (int j = 0; j < A[0].length / 2; j++) { //flip each row and revert the image simultaneously. 8 int temp = A[i][j] ^ 1; 9 A[i][j] = A[i][A[0].length - j - 1] ^ 1; 10 A[i][A[0].length - j - 1] = temp; 11 } 12 if (A.length % 2 != 0) //revert the median of each row if the size of the given matrix is odd. 13 for (int i = 0; i < A.length; i++) 14 A[i][A.length / 2] ^= 1; 15 return A; 16 } 17 }