leetcode 121. Best Time to Buy and Sell Stock

来源:互联网 发布:罗塞塔石碑软件下载 编辑:程序博客网 时间:2024/06/06 04:35
class Solution {public:    int maxProfit(vector<int>& prices) {        int cost = 1000000,ans = 0;        for(int x : prices){            ans = max(ans,x-cost);            if(cost > x)                cost = x;        }        return ans;    }};

0 0
原创粉丝点击