|
1 |
| -# [03.03. Stack of Plates](https://leetcode-cn.com/problems/stack-of-plates-lcci) |
2 |
| - |
3 |
| -## Description |
4 |
| -<p>Imagine a (literal) stack of plates. If the stack gets too high, it might topple. Therefore, in real life, we would likely start a new stack when the previous stack exceeds some threshold. Implement a data structure <code>SetOfStacks</code> that mimics this. <code>SetOfStacks</code> should be composed of several stacks and should create a new stack once the previous one exceeds capacity. <code>SetOfStacks.push()</code> and <code>SetOfStacks.pop()</code> should behave identically to a single stack (that is, <code>pop()</code> should return the same values as it would if there were just a single stack). Follow Up: Implement a function <code>popAt(int index)</code> which performs a pop operation on a specific sub-stack.</p> |
5 |
| -
|
6 |
| -<p>You should delete the sub-stack when it becomes empty. <code>pop</code>, <code>popAt</code> should return -1 when there's no element to pop.</p> |
7 |
| -
|
8 |
| -<p><strong>Example1:</strong></p> |
9 |
| -
|
10 |
| -<pre> |
11 |
| -<strong> Input</strong>: |
12 |
| -["StackOfPlates", "push", "push", "popAt", "pop", "pop"] |
13 |
| -[[1], [1], [2], [1], [], []] |
14 |
| -<strong> Output</strong>: |
15 |
| -[null, null, null, 2, 1, -1] |
16 |
| -<strong> Explanation</strong>: |
17 |
| -</pre> |
18 |
| -
|
19 |
| -<p><strong>Example2:</strong></p> |
20 |
| -
|
21 |
| -<pre> |
22 |
| -<strong> Input</strong>: |
23 |
| -["StackOfPlates", "push", "push", "push", "popAt", "popAt", "popAt"] |
24 |
| -[[2], [1], [2], [3], [0], [0], [0]] |
25 |
| -<strong> Output</strong>: |
26 |
| -[null, null, null, null, 2, 1, 3] |
27 |
| -</pre> |
28 |
| - |
29 |
| - |
30 |
| - |
31 |
| -## Solutions |
32 |
| - |
33 |
| - |
34 |
| -### Python3 |
35 |
| - |
36 |
| -```python |
37 |
| - |
38 |
| -``` |
39 |
| - |
40 |
| -### Java |
41 |
| - |
42 |
| -```java |
43 |
| - |
44 |
| -``` |
45 |
| - |
46 |
| -### ... |
47 |
| -``` |
48 |
| - |
49 |
| -``` |
| 1 | +# [03.03. Stack of Plates](https://leetcode-cn.com/problems/stack-of-plates-lcci) |
| 2 | + |
| 3 | +[中文文档](/lcci/03.03.Stack%20of%20Plates/README.md) |
| 4 | + |
| 5 | +## Description |
| 6 | +<p>Imagine a (literal) stack of plates. If the stack gets too high, it might topple. Therefore, in real life, we would likely start a new stack when the previous stack exceeds some threshold. Implement a data structure <code>SetOfStacks</code> that mimics this. <code>SetOfStacks</code> should be composed of several stacks and should create a new stack once the previous one exceeds capacity. <code>SetOfStacks.push()</code> and <code>SetOfStacks.pop()</code> should behave identically to a single stack (that is, <code>pop()</code> should return the same values as it would if there were just a single stack). Follow Up: Implement a function <code>popAt(int index)</code> which performs a pop operation on a specific sub-stack.</p> |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | +<p>You should delete the sub-stack when it becomes empty. <code>pop</code>, <code>popAt</code> should return -1 when there's no element to pop.</p> |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | +<p><strong>Example1:</strong></p> |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | +<pre> |
| 19 | + |
| 20 | +<strong> Input</strong>: |
| 21 | + |
| 22 | +["StackOfPlates", "push", "push", "popAt", "pop", "pop"] |
| 23 | + |
| 24 | +[[1], [1], [2], [1], [], []] |
| 25 | + |
| 26 | +<strong> Output</strong>: |
| 27 | + |
| 28 | +[null, null, null, 2, 1, -1] |
| 29 | + |
| 30 | +<strong> Explanation</strong>: |
| 31 | + |
| 32 | +</pre> |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | +<p><strong>Example2:</strong></p> |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | +<pre> |
| 41 | + |
| 42 | +<strong> Input</strong>: |
| 43 | + |
| 44 | +["StackOfPlates", "push", "push", "push", "popAt", "popAt", "popAt"] |
| 45 | + |
| 46 | +[[2], [1], [2], [3], [0], [0], [0]] |
| 47 | + |
| 48 | +<strong> Output</strong>: |
| 49 | + |
| 50 | +[null, null, null, null, 2, 1, 3] |
| 51 | + |
| 52 | +</pre> |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | + |
| 57 | +## Solutions |
| 58 | + |
| 59 | + |
| 60 | +### Python3 |
| 61 | + |
| 62 | +```python |
| 63 | + |
| 64 | +``` |
| 65 | + |
| 66 | +### Java |
| 67 | + |
| 68 | +```java |
| 69 | + |
| 70 | +``` |
| 71 | + |
| 72 | +### ... |
| 73 | +``` |
| 74 | +
|
| 75 | +``` |
0 commit comments