Skip to content

Commit ee6cd28

Browse files
authored
Merge pull request doocs#141 from ashwek/master
0832 Flipping an Image - cpp & py
2 parents 8799493 + 2f3fe71 commit ee6cd28

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public:
3+
vector<vector<int>> flipAndInvertImage(vector<vector<int>> &A) {
4+
5+
int temp, Len = A[0].size();
6+
7+
for (int i = 0; i < A.size(); i++)
8+
{
9+
for (int j = 0; j < ((Len + 1) / 2); j++)
10+
{
11+
temp = !A[i][j];
12+
A[i][j] = !A[i][Len - j - 1];
13+
A[i][Len - j - 1] = temp;
14+
}
15+
}
16+
return A;
17+
}
18+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution:
2+
def flipAndInvertImage(self, A):
3+
"""
4+
:type A: List[List[int]]
5+
:rtype: List[List[int]]
6+
"""
7+
8+
Len = len(A[0])
9+
10+
for row in A:
11+
for i in range( (Len + 1) // 2 ):
12+
row[i], row[Len - i - 1] = int(not row[Len - i - 1]), int(not row[i])
13+
14+
return A

0 commit comments

Comments
 (0)