6.14 setMatrixZeroes & gasStation

  • to do

**1] Set Matrix Zeroes **

  • naive 36%
   void setZeroes(vector>& matrix) {
        if (!matrix.size() || !matrix[0].size()) return;
        vector markedRow(matrix.size(), false);
        vector markedCol(matrix[0].size(), false);

        for (int i=0; i

**2] Gas station **
timeout, try dp -> 最大子序列和

    int canCompleteCircuit(vector& gas, vector& 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;
    }

你可能感兴趣的:(6.14 setMatrixZeroes & gasStation)