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;
    }
};
相关推荐
py有趣13 小时前
力扣热门100题之不同路径
算法·leetcode
_日拱一卒13 小时前
LeetCode:25K个一组翻转链表
算法·leetcode·链表
小欣加油13 小时前
leetcode2078 两栋颜色不同且距离最远的房子
数据结构·c++·算法·leetcode·职场和发展
我真不是小鱼14 小时前
cpp刷题打卡记录30——轮转数组 & 螺旋矩阵 & 搜索二维矩阵II
数据结构·c++·算法·leetcode
帅小伙―苏15 小时前
力扣42接雨水
前端·算法·leetcode
6Hzlia16 小时前
【Hot 100 刷题计划】 LeetCode 287. 寻找重复数 | C++ 数组判环 (快慢指针终极解法)
c++·算法·leetcode
穿条秋裤到处跑21 小时前
每日一道leetcode(2026.04.19):下标对中的最大距离
算法·leetcode·职场和发展
木子墨5161 天前
LeetCode 热题 100 精讲 | 计算几何篇:点积叉积 · 线段相交 · 凸包 · 多边形面积
c++·算法·leetcode·职场和发展·动态规划
py有趣1 天前
力扣热门100题之最小路径和
算法·leetcode
im_AMBER1 天前
Leetcode 159 无重复字符的最长子串 | 长度最小的子数组
javascript·数据结构·学习·算法·leetcode