- to do
**1] Set Matrix Zeroes **
- naive 36%
void setZeroes(vector<vector<int>>& matrix) {
if (!matrix.size() || !matrix[0].size()) return;
vector<bool> markedRow(matrix.size(), false);
vector<bool> markedCol(matrix[0].size(), false);
for (int i=0; i<markedRow.size(); ++i) {
for (int j=0; j<markedCol.size(); ++j) {
if (matrix[i][j]==0) {
markedRow[i] = markedCol[j] = true;
}
}
}
for (int i=0; i<markedRow.size(); ++i) {
if (markedRow[i]) {
fill(matrix[i].begin(), matrix[i].end(), 0);
}
}
for (int j=0; j<markedCol.size(); ++j) {
if (markedCol[j]) {
for (int i=0; i<matrix.size(); ++i) {
matrix[i][j] = 0;
}
}
}
}
**2] Gas station **
timeout, try dp -> 最大子序列和
int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {
for (int i = 0; i < gas.size(); ++i) {
// try starting at station i, record at curr station j
int j = i;
int curr = gas[j];
while (curr >= cost[j]) { // still enough to reach next station
curr -= cost[j]; // reach next station
j = (j + 1) % gas.size();
if (j == i) return i;
else curr += gas[j];
}
}
return -1;
}