LeetCode 121. Best Time to Buy and Sell Stock

来源:互联网 发布:境外电视直播软件apk 编辑:程序博客网 时间:2024/05/21 11:18
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;    }}
0 0
原创粉丝点击