-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path832.py
59 lines (40 loc) · 1.21 KB
/
832.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import numpy as np
# Example 1:
# Input: image = [[1,1,0],[1,0,1],[0,0,0]]
# Explanation: First reverse each row: [[0,1,1],[1,0,1],[0,0,0]].
# Then, invert the image: [[1,0,0],[0,1,0],[1,1,1]]
# Example 2:
# Input: image = [[1,1,0,0],[1,0,0,1],[0,1,1,1],[1,0,1,0]]
# Explanation: First reverse each row: [[0,0,1,1],[1,0,0,1],[1,1,1,0],[0,1,0,1]].
# Then invert the image: [[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]]
i = [[1, 1, 0, 0], [1, 0, 0, 1], [0, 1, 1, 1], [1, 0, 1, 0]]
rev_list = []
pix_rev = []
f_l = []
for pix in i:
rev_list.append(pix[::-1])
for pix in rev_list:
for num in pix:
if num == 0:
pix_rev.append(1)
else:
pix_rev.append(0)
f_l.append(pix_rev)
pix_rev = []
print(f_l)
class Solution:
def flipAndInvertImage(self, image: List[List[int]]) -> List[List[int]]:
rev_list = []
pix_rev = []
f_l = []
for pix in image:
rev_list.append(pix[::-1])
for pix in rev_list:
for num in pix:
if num == 0:
pix_rev.append(1)
else:
pix_rev.append(0)
f_l.append(pix_rev)
pix_rev = []
return f_l