From 29c76d70bec88e5262a0f3b26bb60cf55f1b16fb Mon Sep 17 00:00:00 2001 From: Amy Phung Date: Wed, 1 May 2019 21:54:01 -0700 Subject: [PATCH] complete matrix convert to zero method --- lib/matrix_convert_to_zero.rb | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/matrix_convert_to_zero.rb b/lib/matrix_convert_to_zero.rb index 4fb139c..2dffe9e 100644 --- a/lib/matrix_convert_to_zero.rb +++ b/lib/matrix_convert_to_zero.rb @@ -6,5 +6,31 @@ # Time complexity: ? # Space complexity: ? def matrix_convert_to_zero(matrix) - raise NotImplementedError + new_matrix = [] + rows_w_0 = {} + cols_w_0 = {} + + matrix.length.times do |x| + matrix[x].length.times do |y| + if matrix[x][y] == 0 + rows_w_0[x] = true + cols_w_0[y] = true + end + end + end + + matrix.length.times do |x| + matrix[x].length.times do |y| + if rows_w_0[x] == true || cols_w_0[y] == true + matrix[x][y]=0 + else + end + end + end + return matrix end + + + + + \ No newline at end of file