给定一个数组prices,prices[i]代表第i天珠宝的价值,挑一天买再挑一天卖,求最多能赚多少钱。

如果当日珠宝价格小于购入价格,则换成当日购买;
如果当日珠宝价格大于购入价格,则用“temp”记录所赚的的钱。
若temp大于之前的res(之前赚的最多的),则res=temp。

class Solution:def maxProfit(self, prices):""":type prices: List[int]:rtype: int"""if len(prices)<=1:return 0res = 0temp = 0buy = prices[0]i = 1while i<len(prices):if prices[i]<buy:buy = prices[i]else:temp = prices[i]-buy i = i+1if temp>res:res = tempreturn res

13/100. Best Time to Buy and Sell Stock相关推荐

  1. [leetcode]_Best Time to Buy and Sell Stock I II

    一个系列三道题,我都不会做,google之答案.过了两道,第三道看不懂,放置,稍后继续. 一.Best Time to Buy and Sell Stock I 题目:一个数组表示一支股票的价格变换. ...

  2. LeetCode 309. Best Time to Buy and Sell Stock with Cooldown--Java解法-卖股票系列题目

    此文首发于我的Jekyll博客:zhang0peter的个人博客 LeetCode题解文章分类:LeetCode题解文章集合 LeetCode 所有题目总结:LeetCode 所有题目总结 题目地址: ...

  3. LeetCode 123. Best Time to Buy and Sell Stock III--Python解法--动态规划--数学题

    此文首发于我的个人博客:zhang0peter的个人博客 LeetCode题解文章分类:LeetCode题解文章集合 LeetCode 所有题目总结:LeetCode 所有题目总结 题目地址:Best ...

  4. LeetCode 122. Best Time to Buy and Sell Stock II--贪心--Java,C++,Python解法

    题目地址:Best Time to Buy and Sell Stock II - LeetCode Say you have an array for which the ith element i ...

  5. [LeetCOde][Java] Best Time to Buy and Sell Stock III

    题目: Say you have an array for which the ith element is the price of a given stock on day i. Design a ...

  6. LeetCode Best Time to Buy and Sell Stock II

    原题链接在这里:https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/ 题目: Say you have an array ...

  7. leetcode 714. Best Time to Buy and Sell Stock with Transaction Fee | 714. 买卖股票的佳最时机含手续费(递归->傻缓存->dp)

    题目 https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-transaction-fee/ 题解 经典的 暴力递归 - ...

  8. 【LeetCode】 Best Time to Buy and Sell Stock I II III IV 解题报告

    原文地址:http://liangjiabin.com/blog/2015/04/leetcode-best-time-to-buy-and-sell-stock.html Best Time to ...

  9. [LeetCode] Best Time to Buy and Sell Stock 买卖股票的最佳时间

    Say you have an array for which the ith element is the price of a given stock on day i. If you were ...

最新文章

  1. python networkx教程_如何在python中使用networkx绘制有向图?
  2. 【连载】【黑金动力社区原创力作】《液晶驱动与GUI 基础教程》 --序言(一)
  3. ubuntu 运行android sdk 下的工具adb报bash: ./adb: No such file or directory
  4. 我国手机浏览器用户达2.15亿
  5. liunx系统内核安装图形化界面
  6. ei会议论文录用但不参加会议_会议论文投稿可以不参会吗
  7. 【渝粤题库】国家开放大学2021春2717家畜解剖基础题目
  8. 计算机网上作业系统论文,网上作业提交系统的设计与实现
  9. NG Ng-template(模板元素)
  10. 引入dubbo项目接口_Dubbo框架的Hello World
  11. Bailian2977 生理周期【枚举+中国剩余定理】
  12. 对称加密算法和非对称加密算法介绍
  13. integnps 数控智能编程v19.3 数控切割机编程 切割机套料编程
  14. word打开文档很久很慢_word文档 excel文档打开速度比较慢怎么办
  15. tomcat、APR模式
  16. 神棍节献礼之——POJ1111 Image Perimeters(bfs)
  17. 告别硬编码,MySQL 如何实现按某字段的不同取值进行统计?
  18. AlexNet模型及代码详解
  19. 社会热点----清华pk北大
  20. mes系统故障_MES系统解决了什么问题?

热门文章

  1. jaba窗体连接mysql增删改查_知识实现——Java使用jdbc连接MySql数据库,实现增删改查...
  2. mysql选择索引逻辑_Mysql索引选择逻辑
  3. 适合python爬虫使用的浏览器_python爬虫:使用Selenium模拟浏览器
  4. 《Python程序设计》教学大纲
  5. Android APK的加固方法
  6. matplotlib的基本使用1
  7. Python Demo 02 蒙特卡罗方法输出e
  8. sklearn综合示例5:多分类分类器
  9. SVM(support vector machine)支持向量机原理详解
  10. 字节跳动Deep Retrieval召回模型笔记