Skip to content

Commit cb8e0ee

Browse files
Added flipping-image
1 parent 142914f commit cb8e0ee

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

flippin_an_image.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#mysolution
2+
class Solution:
3+
def flipAndInvertImage(self, A: List[List[int]]) -> List[List[int]]:
4+
A_rev = [x[::-1] for x in A]
5+
# print(A_rev)
6+
A_inv = []
7+
for ls in A_rev:
8+
curr, t = ls, []
9+
for i in range(len(curr)):
10+
if curr[i] == 1:
11+
t.append(0)
12+
else:
13+
t.append(1)
14+
A_inv.append(t)
15+
return A_inv
16+
17+
#optimised
18+
class Solution:
19+
def flipAndInvertImage(self, A: List[List[int]]) -> List[List[int]]:
20+
return [[1 ^ i for i in x[::-1]] for x in A]

0 commit comments

Comments
 (0)