leetcode 121. 买卖股票的最佳时机

题目:121. 买卖股票的最佳时机 - 力扣(LeetCode)

加班用手机刷水题,补个记录 +2

复制代码
class Solution {
public:
    int maxProfit(vector<int>& prices) {
        int ret = 0;
        int min = prices[0];
        for (int i = 1; i < prices.size(); i++) {
            if (prices[i] < min) min = prices[i];
            if (prices[i] - min > ret) ret = prices[i] - min;
        }
        return ret;
    }
};
相关推荐
技术卷42 分钟前
详解力扣高频SQL50题之610. 判断三角形【简单】
sql·leetcode·oracle
小新学习屋2 小时前
《剑指offer》-数据结构篇-哈希表/数组/矩阵/字符串
数据结构·leetcode·哈希表
guozhetao3 小时前
【ST表、倍增】P7167 [eJOI 2020] Fountain (Day1)
java·c++·python·算法·leetcode·深度优先·图论
吃着火锅x唱着歌3 小时前
LeetCode 611.有效三角形的个数
算法·leetcode·职场和发展
技术卷3 小时前
详解力扣高频SQL50题之619. 只出现一次的最大数字【简单】
sql·leetcode·oracle
qq_5139704410 小时前
力扣 hot100 Day56
算法·leetcode
爱喝矿泉水的猛男13 小时前
非定长滑动窗口(持续更新)
算法·leetcode·职场和发展
YuTaoShao14 小时前
【LeetCode 热题 100】131. 分割回文串——回溯
java·算法·leetcode·深度优先
大锦终16 小时前
【算法】前缀和经典例题
算法·leetcode
cccc来财17 小时前
Java实现大根堆与小根堆详解
数据结构·算法·leetcode