1
class Solution:
2

3
def calcScore(self):
4
score = 0
5

6
for row in self.grid:
7
for i in range(self.width):
8
score += row[i] * (2 ** (self.width - i - 1))
9
return score
10

11
def flipRow(self, row):
12
for i in range(self.width):
13
self.grid[row][i] = int(not self.grid[row][i])
14

15
def flipCol(self, col):
16
for i in range(self.height):
17
self.grid[i][col] = int(not self.grid[i][col])
18

19
def colSum(self, col):
20
total = 0
21

22
for i in range(self.height):
23
total += self.grid[i][col]
24

25
return total
26

27
def matrixScore(self, grid: List[List[int]]) -> int:
28
self.grid = grid
29
self.height = len(grid)
30
self.width = len(grid[0])
31

32
for r in range(self.height):
33
if not self.grid[r][0]:
34
if not self.grid[r][0]:
35
self.flipRow(r)
36

37
for c in range(1, self.width):
38
colSum = self.colSum(c)
39

40
if colSum < ceil(self.height / 2):
41
self.flipCol(c)
42

43
return self.calcScore()

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0