0301-0310

301. Remove Invalid Parentheses $\star\star\star$

302. Smallest Rectangle Enclosing Black Pixels $\star\star\star$

303. Range Sum Query - Immutable $\star$

304. Range Sum Query 2D - Immutable $\star\star$

305. Number of Islands II $\star\star\star$

306. Additive Number $\star\star$

307. Range Sum Query - Mutable $\star\star$

308. Range Sum Query 2D - Mutable $\star\star\star$

309. Best Time to Buy and Sell Stock with Cooldown $\star\star$

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
class Solution {
 public:
  int maxProfit(vector<int>& prices) {
    int sell = 0;
    int hold = INT_MIN;
    int prev = 0;

    for (int price : prices) {
      int cache = sell;
      sell = max(sell, hold + price);
      hold = max(hold, prev - price);
      prev = cache;
    }

    return sell;
  }
};

310. Minimum Height Trees $\star\star$