# Write all codes of dietpepsi's thinking process

• @dietpepsi , He writes in https://discuss.leetcode.com/topic/30421/share-my-thinking-process , I think it will be easy to understand if we can see all the codes of his thinking process. Maybe helpful.

Version 1:

`````` public int maxProfit(int[] prices) {
if(prices == null || prices.length <= 1)    return 0;
int n = prices.length;
//Solution 1
int[] sell = new int[prices.length];
int[]  rest = new int[prices.length];
sell[0] = 0;
rest[0] = 0;
for(int i = 1; i < n; i ++) {
sell[i] = Math.max(buy[i - 1] + prices[i], sell[i - 1]);
rest[i] = sell[i - 1];
}
return Math.max(sell[n - 1], rest[n - 1]);
}
``````

Solution 2

`````` public int maxProfit(int[] prices) {
if(prices == null || prices.length <= 1)    return 0;
int n = prices.length;
//Solution 2
int[] sell = new int[prices.length];
sell[0] = 0;
sell[1] = Math.max(sell[0], prices[1] - prices[0]);
for(int i = 2; i < n; i ++) {
sell[i] = Math.max(buy[i - 1] + prices[i], sell[i - 1]);
}
return sell[n - 1];
}
``````
``````public int maxProfit(int[] prices) {
if(prices == null || prices.length <= 1)    return 0;
int n = prices.length;
//Solution 3
int sell = 0;
int prev_sell = 0;