-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetMatrixZeroes.cpp
More file actions
executable file
·60 lines (49 loc) · 1.3 KB
/
SetMatrixZeroes.cpp
File metadata and controls
executable file
·60 lines (49 loc) · 1.3 KB
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
//
// SetMatrixZeroes.cpp
// leetcode
//
// Created by witwolf on 5/4/15.
// Copyright (c) 2015 witwolf. All rights reserved.
//
#include <vector>
#include <cstdlib>
#include <ctime>
#include <utility>
#include <ctime>
#include <iostream>
#include <utility>
#include <set>
using namespace std;
class Solution {
public:
time_t setZeroes(vector<vector<char> > &matrix) {
time_t start = time(0);
const size_t rows = matrix.size();
const size_t columns = matrix[0].size();
vector<bool> rowFlag(rows,false);
vector<bool> columnFlag(columns,false);
for(int i = 0 ; i < rows; ++i){
for(int j = 0 ; j < columns ; ++j){
if(matrix[i][j] == 0){
rowFlag[i] = true;
columnFlag[j] = true;
}
}
}
for(int i = 0 ; i < rows; ++i){
if(rowFlag[i] ){
for(int j = 0 ; j < columns ; ++j){
matrix[i][j] = 0;
}
}
}
for(int j = 0 ; j < columns ; ++j){
if(columnFlag[j] ){
for(int i = 0 ; i < rows ; ++ i){
matrix[i][j] = 0;
}
}
}
return time(0) - start;
}
};