Day 18 LeetCode
👨‍💻

Day 18 LeetCode

Tags
Data Structures
Python
Java
Computer Science
Published
Jan 24, 2021

Day 18 Task:

Solutions:

class Solution:
    def setZeroes(self, matrix: List[List[int]]) -> None:
        """
        Do not return anything, modify matrix in-place instead.
        """
        def rowToZero(arr):
            for i in range(len(arr)):
                arr[i] = 0
                
        def columnElementToZero(arr, x):
            for i in range(len(arr)):
                arr[i][x] = 0
                
        zloc = []
                
        for i in range(len(matrix)):
            for j in range(len(matrix[i])):
                if(matrix[i][j] == 0):
                    zloc.append([i,j])
                    
        for i in range(len(zloc)):
            columnElementToZero(matrix, zloc[i][1])
            
        for i in range(len(zloc)):
            rowToZero(matrix[zloc[i][0]])