Skip to content

Commit 2ca195e

Browse files
Create README - LeetHub
1 parent 2b6facd commit 2ca195e

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

0937-online-stock-span/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<h2><a href="https://leetcode.com/problems/online-stock-span">937. Online Stock Span</a></h2><h3>Medium</h3><hr><p>Design an algorithm that collects daily price quotes for some stock and returns <strong>the span</strong> of that stock&#39;s price for the current day.</p>
2+
3+
<p>The <strong>span</strong> of the stock&#39;s price in one day is the maximum number of consecutive days (starting from that day and going backward) for which the stock price was less than or equal to the price of that day.</p>
4+
5+
<ul>
6+
<li>For example, if the prices of the stock in the last four days is <code>[7,2,1,2]</code> and the price of the stock today is <code>2</code>, then the span of today is <code>4</code> because starting from today, the price of the stock was less than or equal <code>2</code> for <code>4</code> consecutive days.</li>
7+
<li>Also, if the prices of the stock in the last four days is <code>[7,34,1,2]</code> and the price of the stock today is <code>8</code>, then the span of today is <code>3</code> because starting from today, the price of the stock was less than or equal <code>8</code> for <code>3</code> consecutive days.</li>
8+
</ul>
9+
10+
<p>Implement the <code>StockSpanner</code> class:</p>
11+
12+
<ul>
13+
<li><code>StockSpanner()</code> Initializes the object of the class.</li>
14+
<li><code>int next(int price)</code> Returns the <strong>span</strong> of the stock&#39;s price given that today&#39;s price is <code>price</code>.</li>
15+
</ul>
16+
17+
<p>&nbsp;</p>
18+
<p><strong class="example">Example 1:</strong></p>
19+
20+
<pre>
21+
<strong>Input</strong>
22+
[&quot;StockSpanner&quot;, &quot;next&quot;, &quot;next&quot;, &quot;next&quot;, &quot;next&quot;, &quot;next&quot;, &quot;next&quot;, &quot;next&quot;]
23+
[[], [100], [80], [60], [70], [60], [75], [85]]
24+
<strong>Output</strong>
25+
[null, 1, 1, 1, 2, 1, 4, 6]
26+
27+
<strong>Explanation</strong>
28+
StockSpanner stockSpanner = new StockSpanner();
29+
stockSpanner.next(100); // return 1
30+
stockSpanner.next(80); // return 1
31+
stockSpanner.next(60); // return 1
32+
stockSpanner.next(70); // return 2
33+
stockSpanner.next(60); // return 1
34+
stockSpanner.next(75); // return 4, because the last 4 prices (including today&#39;s price of 75) were less than or equal to today&#39;s price.
35+
stockSpanner.next(85); // return 6
36+
</pre>
37+
38+
<p>&nbsp;</p>
39+
<p><strong>Constraints:</strong></p>
40+
41+
<ul>
42+
<li><code>1 &lt;= price &lt;= 10<sup>5</sup></code></li>
43+
<li>At most <code>10<sup>4</sup></code> calls will be made to <code>next</code>.</li>
44+
</ul>

0 commit comments

Comments
 (0)