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;
    }
};
相关推荐
普通攻击往后拉3 小时前
Leetcode 206. 反转链表
算法·leetcode·链表
橘子汽水16810 小时前
Leetcode 230,98:二叉搜索树中第K小的元素,验证二叉搜索树
算法·leetcode·职场和发展
普通攻击往后拉12 小时前
Leetcode 448. 找到所有数组中消失的数字
算法·leetcode·职场和发展
mifengxing12 小时前
LeetCode 189 轮转数组|3种解法拆解,从暴力到O(1)原地最优解
数据结构·算法·leetcode
程序员-珍14 小时前
力扣 877. 石子游戏
算法·leetcode·游戏
wabs66614 小时前
关于链表【力扣19.删除链表的倒数第N个节点的思考】
数据结构·leetcode·链表
Rabitebla14 小时前
C++ STL 之 set 详解:从底层红黑树到实际应用
开发语言·数据结构·c++·算法·leetcode
郝学胜-神的一滴15 小时前
力扣 692:巧用小顶堆高效求解前K个高频单词
java·数据结构·python·程序人生·算法·leetcode·职场和发展
Hi李耶1 天前
【LeetCode】4-寻找两个正序数组的中位数
算法·leetcode·职场和发展
Hi李耶1 天前
【LeetCode】6-Z字形变换
算法·leetcode·职场和发展