public class MaxProfit {
public int maxProfit(int[] prices) {
int[] dp=new int[prices.length+1];
dp[0]=0;
int min=Integer.MAX_VALUE;
for (int i = 0; i <prices.length ; i++) {
if (prices[i]<min)min=prices[i];
dp[i+1]=Math.max(dp[i],prices[i]-min);
}
return dp[dp.length-1];
}
public static void main(String[] args) {
MaxProfit a=new MaxProfit();
int[] b={7,1,5,3,6,4};
System.out.println(a.maxProfit(b));
}