班级动态网站怎么做手机如何创建网站
动态规划
class Solution:def maxProfit(self, prices):pre = float('inf')ans = 0for now in prices:if now > pre:ans += now - prepre = nowreturn ans
定义一个变量保存上一步位置最小的数值,来模拟dp
--遍历股票数值
--如果当前数值大于上一次,将股票卖出,盈利为而二者差值
--然后将上一步数值改为当前数值
动态规划
class Solution:def maxProfit(self, prices):pre = float('inf')ans = 0for now in prices:if now > pre:ans += now - prepre = nowreturn ans
定义一个变量保存上一步位置最小的数值,来模拟dp
--遍历股票数值
--如果当前数值大于上一次,将股票卖出,盈利为而二者差值
--然后将上一步数值改为当前数值