public class Solution {
public int maxProfit(int[] prices) {
if(prices.length==0){
return 0;
}
int maxProfit = 0;
int min = prices[0];
for(int i = 1;i<prices.length;i++){
if(min<=prices[i]){
maxProfit = Math.max(maxProfit,prices[i]-min);
}else{
min = prices[i];
}
}
return maxProfit;
}
}