forked from iamshubhamg/Leet-Code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlippingImage.java
More file actions
28 lines (25 loc) · 763 Bytes
/
Copy pathFlippingImage.java
File metadata and controls
28 lines (25 loc) · 763 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
/* Solving Que. 832. Flipping an Image : https://leetcode.com/problems/flipping-an-image/ */
import java.util.Arrays;
public class FlippingImage {
public static void main(String[] args) {
int[][] arr = {
{1,1,0,0},
{1,0,0,1},
{0,1,1,1},
{1,0,1,0}
};
int c = arr[0].length;
for (int[] row : arr) {
for (int i = 0; i < (c+1)/2 ; i++) {
int tmp = row[i];
row[i] = 1 - row[c-1-i];
row[c-1-i] = 1 - tmp;
}
}
// printing the final answer
for(int row = 0; row < arr.length ; row++)
{
System.out.println(Arrays.toString(arr[row]));
}
}
}