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

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

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

#include <iostream>
using namespace std;

int main() 
{
    int n = 0;
    cin >> n;
    int prices[n];
    for (int i = 0; i < n && cin >> prices[i]; i++);

    int max = 0;
    int money = 0;
    int min = prices[0];
    for (int i = 1; i < n; i++)
    {
        money = prices[i] - min;
        if (money > max)
        {
            max = money;
        }
        if (money < 0)
        {
            min = prices[i];
        }
    }

    cout << max;
    return 0;
}

全部评论

相关推荐

牛客83265014...:完了,连现在都没开始面,13号投的是不是晚了
秋招的第一个offer,...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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