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;
    }
};
相关推荐
历程里程碑1 天前
普通数组----合并区间
java·数据结构·python·算法·leetcode·职场和发展·tornado
iAkuya1 天前
(leetcode)力扣100 61分割回文串(回溯,动归)
算法·leetcode·职场和发展
VT.馒头1 天前
【力扣】2695. 包装数组
前端·javascript·算法·leetcode·职场和发展·typescript
Charlie_lll1 天前
力扣解题-移动零
后端·算法·leetcode
iAkuya1 天前
(leetcode)力扣100 62N皇后问题 (普通回溯(使用set存储),位运算回溯)
算法·leetcode·职场和发展
YuTaoShao1 天前
【LeetCode 每日一题】3634. 使数组平衡的最少移除数目——(解法一)排序+滑动窗口
算法·leetcode·排序算法
TracyCoder1231 天前
LeetCode Hot100(27/100)——94. 二叉树的中序遍历
算法·leetcode
草履虫建模2 天前
力扣算法 1768. 交替合并字符串
java·开发语言·算法·leetcode·职场和发展·idea·基础
VT.馒头2 天前
【力扣】2721. 并行执行异步函数
前端·javascript·算法·leetcode·typescript
不穿格子的程序员2 天前
从零开始写算法——普通数组篇:缺失的第一个正数
算法·leetcode·哈希算法