-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFlippingImage.cpp
43 lines (36 loc) · 988 Bytes
/
FlippingImage.cpp
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
42
43
// https://leetcode.com/problems/flipping-an-image/
vector<vector<int>> flipAndInvertImage(vector<vector<int>>& A) {
int len = A.size();
for (int i = 0; i < len; i++) {
for (int j = 0; j * 2 < len; j++) {
if (A[i][j] == A[i][len - j - 1]) {
A[i][j] ^= 1;
A[i][len - j - 1] = A[i][j];
}
}
}
return A;
}
vector<vector<int>> flipAndInvertImage(vector<vector<int>>& A) {
int row = A.size(), col = A[0].size();
for (int i = 0; i < row; i++)
for (int j = 0; j <= (col - 1) / 2; j++)
{
int temp = A[i][j];
A[i][j] = !A[i][col - j - 1];
A[i][col - j - 1] = !temp;
}
return A;
}
vector<vector<int>> flipAndInvertImage(vector<vector<int>>& A) {
for (auto& v : A) {
reverse(v.begin(), v.end());
for (auto& n : v)
n = !n;
}
return A;
}
vector<vector<int>> flipAndInvertImage(vector<vector<int>>& A) {
for_each(A.begin(), A.end(), [](auto & r) {reverse(r.begin(), r.end()); for_each(r.begin(), r.end(), [](auto & n) {n = !n;});});
return A;
}