public int maxProfit_DP(int[] prices) {

    if (prices.length == 0) {
      return 0;
    }

    int[] dp = new int[prices.length];

    int max = 0;
    int minPrice = prices[0];
    for (int i = 1 ; i < prices.length ; i++) {
      dp[i] = Math.max(dp[i - 1], prices[i] - minPrice);
      minPrice = Math.min(minPrice, prices[i]);

      if (dp[i] > max) {
        max = dp[i];
      }
    }

    return max;
  }