这是悦乐书的第173次更新,第175篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第32题(顺位题号是122).假设有一个数组,其中第i个元素是第i天给定股票的价格.设计算法以找到最大利润.可以根据需要完成尽可能多的交易(即,多次买入并卖出一股股票). 注意:不能同时进行多笔交易(即,您必须在再次购买之前卖出股票). 例如: 输入:[7,1,5,3,6,4] 输出:7 说明:在第2天买入(价格= 1)并在第3天卖出(价格= 5),利润= 5-1 = 4.然后在第4天…
这是悦乐书的第172次更新,第174篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第31题(顺位题号是121).假设有一个数组,其中第i个元素是第i天给定股票的价格.如果只被允许完成最多一笔交易(即买入并卖出一股股票),请设计算法以找到最大利润.请注意,在购买之前不能出售股票.例如: 输入:[7,1,5,3,6,4] 输出:5 说明:在第2天买入(价格= 1)并在第5天卖出(价格= 6),利润= 6-1 = 5.不是7-1 = 6,因为售价需要大于购买价格. 输入:…
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete as m…
Best Time to Buy and Sell Stock IV Say you have an array for which the i-th element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete at most k transactions. Note: You may not engage in multiple…
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 an algorithm to find the maximum profit. You may complete at most two transactions. Note: You may not engage in multipl…
Best Time to Buy and Sell Stock II Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i.e., buy one and sell one s…
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 only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), design an algorith…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 动态规划 日期 题目地址:https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown/description/ 题目描述 Say you have an array for which the ith element is the price of a giv…
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. Design an algorithm to find the maximum profit. You may complete at most two transactions. Note: You may not engage in multiple tr…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iv/description/ 题目描述 Say you have an array for which the ith element is the price of a given stock on day…