Created
May 26, 2018 21:12
-
-
Save BiruLyu/47059846739cf82f11cb92bf04ffde2a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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