public int maxProfit(int[] prices) { int max = 0 , min = Integer.MAX_VALUE; for(int num : prices) { max = Math.max(max,num - min); min = Math.min(min,num); } return max; }
public int maxProfit(int[] prices) { int max = 0 , min = Integer.MAX_VALUE; for(int num : prices) { max = Math.max(max,num - min); min = Math.min(min,num); } return max; }