-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path73.set-matrix-zeroes.c
65 lines (51 loc) · 1.29 KB
/
73.set-matrix-zeroes.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* @lc app=leetcode id=73 lang=c
*
* [73] Set Matrix Zeroes
*/
// @lc code=start
#include <stdio.h>
#include <memory.h>
// #define DEBUG
void setZeroes(int** matrix, int matrixSize, int* matrixColSize){
int rowFlags[matrixSize];
int colFlags[*matrixColSize];
memset(rowFlags, 0, sizeof(int) * matrixSize);
memset(colFlags, 0, sizeof(int) * *matrixColSize);
for (int i = 0; i < matrixSize; i++) {
for (int j = 0; j < *matrixColSize; j++) {
if (matrix[i][j] == 0) {
rowFlags[i] = 1;
colFlags[j] = 1;
}
}
}
for (int i = 0; i < matrixSize; i++) {
if (rowFlags[i] == 1) {
for (int j = 0; j < *matrixColSize; j++) {
matrix[i][j] = 0;
}
}
}
for (int i = 0; i < *matrixColSize; i++) {
if (colFlags[i] == 1) {
for (int j = 0; j < matrixSize; j++) {
matrix[j][i] = 0;
}
}
}
#ifdef DEBUG
printf("\n");
#endif
for (int i = 0; i < matrixSize; i++) {
for (int j = 0; j < *matrixColSize; j++) {
#ifdef DEBUG
printf("%d, ", matrix[i][j]);
#endif
}
#ifdef DEBUG
printf("\n");
#endif
}
}
// @lc code=end