Leetcode中股票问题合集

Best Time to Buy and Sell Stock II 思路:这道题用到了贪心算法。从次日开始,只要比前一天大,那说明就挣钱,那么就前一天买今天卖,挣差价。 int maxProfit(vector<int>& prices) { int res = 0; int n = prices.size(); for (int i = 0; i
相关文章
相关标签/搜索