classSolution: defonesMinusZeros(self, grid: List[List[int]]) -> List[List[int]]: n = len(grid) m = len(grid[0]) r = [sum(grid[i]) for i inrange(n)] c = [0for _ inrange(m)] for j inrange(m): tmp = 0 for i inrange(n): tmp += grid[i][j] c[j] = tmp ans = [[0for i inrange(m)] for j inrange(n)] for i inrange(n): for j inrange(m): ans[i][j] = r[i] + c[j] - (n + m - r[i] - c[j]) return ans
classSolution: defbestClosingTime(self, customers: str) -> int: y = customers.count('Y') n = customers.count('N') ans, cost = -1, y tmp = 0 cy, cn = 0, 0 for i inrange(len(customers)): if customers[i] == 'Y': cy += 1 else: cn += 1 if cost > cn + y - cy: cost = cn + y - cy ans = i return ans + 1