-
-
Notifications
You must be signed in to change notification settings - Fork 300
/
832.java
32 lines (31 loc) · 1.12 KB
/
832.java
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
__________________________________________________________________________________________________
sample 0 ms submission
class Solution {
public int[][] flipAndInvertImage(int[][] A) {
for(int i = 0; i < A.length; i++){
for(int j = 0, k = A[0].length - 1; j <= k; j++, k--){
int temp = (A[i][j] > 0 ? 0 : 1);
A[i][j] = (A[i][k] > 0 ? 0 : 1);
A[i][k] = temp;
}
}
return A;
}
}
__________________________________________________________________________________________________
sample 35228 kb submission
class Solution {
public int[][] flipAndInvertImage(int[][] A) {
for(int i = 0; i< A.length; i++){
int[] a = A[i];
ArrayList<Integer> list = new ArrayList<Integer>();
for(int j = 0; j < a.length; j++){
int v = a[a.length - 1 - j];
list.add(v ^ 1);
}
A[i] = list.stream().mapToInt(x -> x).toArray();
}
return A;
}
}
__________________________________________________________________________________________________