Leetcode 121. Best Time to Buy and Sell Stock

原题地址

https://leetcode.com/problems/best-time-to-buy-and-sell-stock/description/

题意

给定数组prices[],找出i,j(i

思路

就是扫一遍数组,不断更新出现的最小值和和最小值的最大差值了 (并没意识到这个也算动态规划

代码

class Solution {
public:
    int maxProfit(vector& prices) {
        int n = prices.size();
        if(n==0) return 0;
        int result =0;
        int low=prices[0];
        for(int i =1;iresult){
                    result = temp;
                }
            }
        }
        return result;
    }
};

你可能感兴趣的:(Leetcode 121. Best Time to Buy and Sell Stock)