题解 | #买卖股票的最好时机(一)#

买卖股票的最好时机(一)

https://www.nowcoder.com/practice/351b87e53d0d44928f4de9b6217d36bb

#include <iostream>
using namespace std;

const int N = 100010;
int a[N];

int main() {
    int n;
    cin >> n;
    for(int i = 0; i < n; i ++){
        cin >> a[i];
    }
    int minPrice = 1e9, maxProfit = -1e9;
    for(int i = 0; i < n; i ++){
        minPrice = min(a[i], minPrice);
        maxProfit = max(maxProfit, a[i] - minPrice);
    }
    cout << maxProfit << endl;
    return 0;
}

全部评论

相关推荐

asdasdasda...:19岁,不容易啊可能升个本会好点,现在学历歧视太严重了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务