这是悦乐书的第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,因为售价需要大于购买价格. 输入:…
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…
一天一道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…
转载请注明出处:z_zhaojun的博客 原文地址 题目地址 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 lik…
Problem Link: http://oj.leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/ We solve this problem using Greedy Algorithm, which only scan the prices list once. The worst-case running time is O(n). According to the problem description, we know t…
题目: 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 (ie, buy one and sell one share of the stock multiple times)…
1. 题目 1.1 英文题目 You are given an array prices where prices[i] is the price of a given stock on the ith day. Find the maximum profit you can achieve. You may complete as many transactions as you like (i.e., buy one and sell one share of the stock multi…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/#/description 题目描述 Say you have an array for which the ith element is the price of a given stock on day…
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 (ie, buy one and sell one share of the stock multiple times). Ho…