-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlippingAnImage.java
More file actions
29 lines (23 loc) · 860 Bytes
/
FlippingAnImage.java
File metadata and controls
29 lines (23 loc) · 860 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
package com.company;
import java.util.Arrays;
public class FlippingAnImage {
public static void main(String[] args) throws Exception {
int[][] points = {{1, 1, 0}, {1, 0, 1}, {0, 0, 0}};
System.out.println(Arrays.deepToString(points));
System.out.println(Arrays.deepToString(flipAndInvertImage(points)));
}
public static int[][] flipAndInvertImage(int[][] A) {
for (int i = 0; i < A.length; i++) {
int[] pixels = A[i];
for (int j = 0; j < pixels.length / 2; j++) {
int temp = pixels[j];
pixels[j] = pixels[pixels.length - j - 1];
pixels[pixels.length - j - 1] = temp;
}
for (int x = 0; x < pixels.length; x++) {
pixels[x] = pixels[x] == 0 ? 1 : 0;
}
}
return A;
}
}