## Buying and selling stock leetcode

121. 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 (ie, buy one and sell one share of the stock), design an algorithm to find the maximum profit. LeetCode – Best Time to Buy and Sell Stock III (Java) 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. 122 Best Time to Buy and Sell Stock II. 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 as many transactions as you like (ie, buy one and sell one share of the stock multiple times).

## leetcode 100 斩！回顾 1. Two Sum 2. Add Two Numbers 3. Longest Substring Without Repeating Characters Best Time to Buy and Sell Stock II 123*. Best Time to Buy and Sell Stock III 124*. Binary Tree Maximum Path Sum 125. Valid Palindrome

Maximum profit gained by selling on the i'th day. In order to sell shares on the i'th day, we need to purchase it on any one of previous days. If we buy shares on the   10 Jul 2014 Solution to Best Time to Buy and Sell Stock II by LeetCode. 10 Jul. Posted on July 10, 2014  6 Jan 2016 Leetcode: Best Time to Buy and Sell Stock with Cooldown. Say you have an array for which the ith element is the price of a given stock on day i. 2017年11月11日 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  题目难度：简单; 通过次数：161.1K; 提交次数：300.6K; 贡献者：LeetCode. 相关标签. 数组动态规划. 相似题目. 最大子序和买卖股票的最佳时机II买卖股票的最佳时机III  28 Oct 2019 You may complete as many transactions as you like (ie, buy one and sell one share of the stock multiple times) with the following restrictions:. 16 Jan 2013 [LeetCode] Best Time to Buy and Sell Stock Solution. Say you have an array for which the i th 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

1) It runs in linear time and linear space 2) buy[0] is being initialized to -prices[0] (minus price of first stock), because we are assuming to have bought the first stock at the end of first day