Skip to content

Commit ecd8804

Browse files
Create README - LeetHub
1 parent a7e7a29 commit ecd8804

File tree

1 file changed

+31
-0
lines changed
  • 0121-best-time-to-buy-and-sell-stock

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<h2><a href="https://leetcode.com/problems/best-time-to-buy-and-sell-stock">121. Best Time to Buy and Sell Stock</a></h2><h3>Easy</h3><hr><p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p>
2+
3+
<p>You want to maximize your profit by choosing a <strong>single day</strong> to buy one stock and choosing a <strong>different day in the future</strong> to sell that stock.</p>
4+
5+
<p>Return <em>the maximum profit you can achieve from this transaction</em>. If you cannot achieve any profit, return <code>0</code>.</p>
6+
7+
<p>&nbsp;</p>
8+
<p><strong class="example">Example 1:</strong></p>
9+
10+
<pre>
11+
<strong>Input:</strong> prices = [7,1,5,3,6,4]
12+
<strong>Output:</strong> 5
13+
<strong>Explanation:</strong> Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5.
14+
Note that buying on day 2 and selling on day 1 is not allowed because you must buy before you sell.
15+
</pre>
16+
17+
<p><strong class="example">Example 2:</strong></p>
18+
19+
<pre>
20+
<strong>Input:</strong> prices = [7,6,4,3,1]
21+
<strong>Output:</strong> 0
22+
<strong>Explanation:</strong> In this case, no transactions are done and the max profit = 0.
23+
</pre>
24+
25+
<p>&nbsp;</p>
26+
<p><strong>Constraints:</strong></p>
27+
28+
<ul>
29+
<li><code>1 &lt;= prices.length &lt;= 10<sup>5</sup></code></li>
30+
<li><code>0 &lt;= prices[i] &lt;= 10<sup>4</sup></code></li>
31+
</ul>

0 commit comments

Comments
 (0)