-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlipping_an_Image_832.java
More file actions
41 lines (34 loc) · 867 Bytes
/
Flipping_an_Image_832.java
File metadata and controls
41 lines (34 loc) · 867 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
32
33
34
35
36
37
38
39
40
41
package leetcode;
import java.util.Arrays;
class Solution832 {
public int[][] flipAndInvertImage(int[][] image) {
for(int row[]:image) {
for(int i=0;i<row.length/2;i++) {
int temp=row[i];
row[i]=row[row.length-1-i];
row[row.length-1-i]=temp;
}
for(int i=0;i<row.length;i++) {
if(row[i]==1) {
row[i]=0;
}
else {
row[i]=1;
}
}
}
return image;
}
}
//[[1,0,0],[0,1,0],[1,1,1]]
public class Flipping_an_Image_832 {
public static void main(String[] args) {
Solution832 ns=new Solution832();
// int [][] image={{1,1,0},{1,0,1},{0,0,0}};
int [][] image= {{1,1,0,0},{1,0,0,1},{0,1,1,1},{1,0,1,0}};
int[][] flipped=ns.flipAndInvertImage(image);
for(int [] row:flipped) {
System.out.println(Arrays.toString(row));
}
}
}