-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathFlippingAnImage.java
More file actions
31 lines (28 loc) · 843 Bytes
/
FlippingAnImage.java
File metadata and controls
31 lines (28 loc) · 843 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package matrix;
// Source : https://leetcode.com/problems/flipping-an-image/
// Id : 832
// Author : Fanlu Hai | https://github.com/Fanlu91/FanluLeetcode
// Date : 2019-06-04
// Topic : Matrix
// Other :
// Tips : int a[][] = new int[3][4]; //3行 4列
// int lenY = a.length; // 3
// Result : 100.00% 99.95%
public class FlippingAnImage {
public int[][] flipAndInvertImage(int[][] A) {
for (int i = 0; i < A.length; i++) {
int head = 0, tail = A[0].length - 1;
while (tail > head) {
if (A[i][tail] == A[i][head]) {
A[i][tail] ^= 1;
A[i][head] ^= 1;
}
tail--;
head++;
}
if (tail == head)
A[i][tail] ^= 1;
}
return A;
}
}