每日一题11
题目:
121. 买卖股票的最佳时机
思路:找出最低值,然后再找出其后的最高值即可!
class Solution {
public int maxProfit(int[] prices) {
int max=0;
int n=prices.length;
int min=100000;
for(int i=0;i<n;++i){
if(prices[i]<min){
min=prices[i];
}else{
if(prices[i]-min>max){
max=prices[i]-min;
}
}
}
return max;
}
}
标签:11,min,int,max,每日,prices,一题
From: https://www.cnblogs.com/ZLey/p/17196320.html