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;
    }
};
相关推荐
To_OC1 分钟前
LC 1 两数之和:面试第一道必考题,暴力解法直接被面试官 pass
javascript·算法·leetcode
想吃火锅10056 天前
【leetcode】121.买卖股票的最佳时机js/c++
算法·leetcode·职场和发展
凌波粒6 天前
LeetCode--491.递增子序列(回溯算法)
数据结构·算法·leetcode
退休倒计时6 天前
【每日一题】LeetCode 146. LRU 缓存 TypeScript
算法·leetcode·缓存·typescript
小欣加油6 天前
leetcode3612 用特殊操作处理字符串I
数据结构·c++·算法·leetcode·职场和发展
凌波粒6 天前
LeetCode--90.子集II(回溯算法)
数据结构·算法·leetcode
凌波粒6 天前
LeetCode--46.全排列(回溯算法)
数据结构·算法·leetcode
吃着火锅x唱着歌6 天前
LeetCode 2530.执行K次操作后的最大分数
数据结构·算法·leetcode
sheeta19986 天前
LeetCode 每日一题笔记 日期:2026.06.16 题目:3612. 字符串特殊符号处理
笔记·算法·leetcode
CoderYanger6 天前
A.每日一题:2095. 删除链表的中间节点
java·数据结构·程序人生·leetcode·链表·面试·职场和发展