import java.util.*;
public class Solution {
public int maxProfit (int[] prices) {
// write code here
if(prices==null||prices.length==0||prices.length==1)
return 0;
int max=0;
int[] dp = new int[prices.length];
for(int i=1;i<prices.length;++i){
dp[i] = Math.max(dp[i-1]+prices[i]-prices[i-1],0);
max = Math.max(dp[i],max);
}
return max;
}
}