Skip to content

Instantly share code, notes, and snippets.

@lewang
Created January 24, 2013 04:11
Show Gist options
  • Save lewang/4617559 to your computer and use it in GitHub Desktop.
Save lewang/4617559 to your computer and use it in GitHub Desktop.

zero out values in matrix

Given a NxN matrix, with 0s and 1s, set every row that contains a 0 to all 0s and every column that contains a 0 to all 0s.

For example:

Input for N==5

1 0 1 1 0
0 1 1 1 0
1 1 1 1 1
1 0 1 1 1
1 1 1 1 1

results in

0 0 0 0 0
0 0 0 0 0
0 0 1 1 0
0 0 0 0 0
0 0 1 1 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment