力扣原题
import java.util.*;
public class Solution {
/**
*
* @param prices int整型一维数组
* @return int整型
*/
public int maxProfit (int[] prices) {
// write code here
int low = Integer.MAX_VALUE;
int res = 0;
for (int i = 0; i < prices.length; i++) {
low = Math.min(low, prices[i]);
res = Math.max(res, prices[i] - low);
}
return res;
}
}

京公网安备 11010502036488号