-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem no 832.java
More file actions
31 lines (27 loc) · 842 Bytes
/
Copy pathProblem no 832.java
File metadata and controls
31 lines (27 loc) · 842 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
// Ques : Flip an image
// Ques Link : https://leetcode.com/problems/flipping-an-image/
package com.nitin.bitwise;
import java.util.Arrays;
public class flipImage {
public static void main(String[] args) {
int[][] arr = {
{1,1,0},
{1,0,1},
{0,0,0}
};
int[][] ans = flipAndInvertImage(arr);
System.out.println(Arrays.deepToString(ans));
}
public static int[][] flipAndInvertImage(int[][] arr) {
for (int[] row: arr) {
// reverse this array
for (int i = 0; i < (arr[0].length + 1) / 2; i++) {
// swap
int temp = row[i] ^ 1;
row[i] = row[arr[0].length - i - 1] ^ 1;
row[arr[0].length - i - 1] = temp;
}
}
return arr;
}
}