您当前的位置: 首页 > 

股票问题汇总

对方正在debug 发布时间:2020-02-21 19:31:04 ,浏览量:7

买卖股票的最佳时机

题目:https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock/

class Solution {
public:
    int maxProfit(vector& prices) {
        /*
        *如果你最多只允许完成一笔交易(即买入和卖出
        *一支股票),设计一个算法来计算你所能获取的
        *最大利润。注意你不能在买入股票前卖出股票。
        *一遍扫描,求最大的增值
        */
        int n = prices.size();
        int ans = 0,mn = INT_MAX;
        for(int i = 0;i             
关注
打赏
1688896170
查看更多评论
0.3860s