LeetCode - Algorithms - 832. Flipping an Image

Problem

832. Flipping an Image

similar question : 48. Rotate Image

Java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class Solution {
public int[][] flipAndInvertImage(int[][] A) {
final int N = A.length;
final int M = A[0].length;
int tmp;
for(int i=0; i<N; i++) {
for(int j=0; j<M/2; j++) {
tmp = A[i][j];
A[i][j] = A[i][N-1-j];
A[i][N-1-j] = tmp;
}
}
for(int i=0; i<N; i++) {
for(int j=0; j<M; j++) {
A[i][j] = A[i][j]==0?1:0;
}
}
return A;
}
}

Submission Detail

  • 82 / 82 test cases passed.
  • Runtime: 0 ms, faster than 100.00% of Java online submissions for Flipping an Image.
  • Memory Usage: 39.1 MB, less than 16.27% of Java online submissions for Flipping an Image.