Skip to content

Instantly share code, notes, and snippets.

@BiruLyu
Created May 26, 2018 21:12
Show Gist options
  • Save BiruLyu/47059846739cf82f11cb92bf04ffde2a to your computer and use it in GitHub Desktop.
Save BiruLyu/47059846739cf82f11cb92bf04ffde2a to your computer and use it in GitHub Desktop.
class Solution {
public int[][] flipAndInvertImage(int[][] A) {
if (A == null || A.length < 1 || A[0].length < 1) return A;
int m = A.length, n = A[0].length;
for (int i = 0; i < m; i++) {
for (int j = 0; j < n / 2; j++) {
int temp = A[i][j];
A[i][j] = A[i][n - 1 - j] ^ 1;
A[i][n - 1 - j] = temp ^ 1;
}
if (n % 2 != 0) {
A[i][n / 2] ^= 1;
}
}
return A;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment