public int maxProfit3(int [] prices){
        if(prices == null || prices.length <= 1) return 0;
        int [] diff = new int [prices.length - 1];
        for (int i = 0; i < prices.length - 1; ++i){
            diff[i] = prices[i+1] - prices[i];
        }
        int [] DP = new int[diff.length];
        DP[0] = diff[0] >= 0? diff[0] : 0;
        for (int i = 1; i < diff.length; ++i){
              if (DP[i-1] + diff[i] >= 0){
                  DP[i] = DP[i-1] + diff[i];
              }else {
                  DP[i] =diff[i] >= 0? diff[i] : 0;
              }
        }
        int max = 0;
        for (int i : DP){
            max = Math.max(i, max);
        }
        return max;
    }