Best Time To Buy and Sell Stock

来源:互联网 发布:站长中国源码交易 编辑:程序博客网 时间:2024/05/01 02:36


public class Solution {    public int maxProfit(int[] prices) {        int profit = 0;                if (prices == null || prices.length < 2) {            return profit;        }                int min = Integer.MAX_VALUE;                int cur = 0;                 while (cur < prices.length) {            min = Math.min(min, prices[cur]);            profit = Math.max(profit, prices[cur] - min);            cur++;        }                return profit;    }}


0 0