Skip to content

Commit 3b2a755

Browse files
committed
feat: update lc problems
1 parent 2c3a09c commit 3b2a755

File tree

101 files changed

+1331
-188
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+1331
-188
lines changed

lcci/03.03.Stack of Plates/README.md

+15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# [面试题 03.03. 堆盘子](https://leetcode.cn/problems/stack-of-plates-lcci)
2+
23
[English Version](/lcci/03.03.Stack%20of%20Plates/README_EN.md)
4+
35
## 题目描述
6+
47
<!-- 这里写题目描述 -->
58
<p>堆盘子。设想有一堆盘子,堆太高可能会倒下来。因此,在现实生活中,盘子堆到一定高度时,我们就会另外堆一堆盘子。请实现数据结构<code>SetOfStacks</code>,模拟这种行为。<code>SetOfStacks</code>应该由多个栈组成,并且在前一个栈填满时新建一个栈。此外,<code>SetOfStacks.push()</code>和<code>SetOfStacks.pop()</code>应该与普通栈的操作方法相同(也就是说,pop()返回的值,应该跟只有一个栈时的情况一样)。 进阶:实现一个<code>popAt(int index)</code>方法,根据指定的子栈,执行pop操作。</p>
69
<p>当某个栈为空时,应当删除该栈。当栈中没有元素或不存在该栈时,<code>pop</code>,<code>popAt</code>&nbsp;应返回 -1.</p>
@@ -18,20 +21,29 @@
1821
<strong> 输出</strong>:
1922
[null, null, null, null, 2, 1, 3]
2023
</pre>
24+
2125
## 解法
2226
<!-- 这里可写通用的实现逻辑 -->
27+
2328
<!-- tabs:start -->
29+
2430
### **Python3**
31+
2532
<!-- 这里可写当前语言的特殊实现逻辑 -->
33+
2634
```python
2735

2836
```
2937
### **Java**
38+
3039
<!-- 这里可写当前语言的特殊实现逻辑 -->
40+
3141
```java
3242

3343
```
44+
3445
### **TypeScript**
46+
3547
```ts
3648
class StackOfPlates {
3749
private cap: number;
@@ -84,8 +96,11 @@ class StackOfPlates {
8496
* var param_3 = obj.popAt(index)
8597
*/
8698
```
99+
87100
### **...**
101+
88102
```
89103
90104
```
105+
91106
<!-- tabs:end -->

lcci/03.03.Stack of Plates/README_EN.md

+19-5
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,60 @@
11
# [03.03. Stack of Plates](https://leetcode.cn/problems/stack-of-plates-lcci)
2+
23
[中文文档](/lcci/03.03.Stack%20of%20Plates/README.md)
4+
35
## Description
6+
47
<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.&nbsp;<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>
58
<p>You should delete the sub-stack when it becomes empty. <code>pop</code>, <code>popAt</code> should return -1 when there&#39;s no element to pop.</p>
69
<p><strong>Example1:</strong></p>
710
<pre>
811

9-
<strong> Input</strong>:
12+
<strong> Input</strong>:
1013

1114
[&quot;StackOfPlates&quot;, &quot;push&quot;, &quot;push&quot;, &quot;popAt&quot;, &quot;pop&quot;, &quot;pop&quot;]
1215

1316
[[1], [1], [2], [1], [], []]
1417

15-
<strong> Output</strong>:
18+
<strong> Output</strong>:
1619

1720
[null, null, null, 2, 1, -1]
1821

19-
<strong> Explanation</strong>:
22+
<strong> Explanation</strong>:
2023

2124
</pre>
2225
<p><strong>Example2:</strong></p>
2326
<pre>
2427

25-
<strong> Input</strong>:
28+
<strong> Input</strong>:
2629

2730
[&quot;StackOfPlates&quot;, &quot;push&quot;, &quot;push&quot;, &quot;push&quot;, &quot;popAt&quot;, &quot;popAt&quot;, &quot;popAt&quot;]
2831

2932
[[2], [1], [2], [3], [0], [0], [0]]
3033

31-
<strong> Output</strong>:
34+
<strong> Output</strong>:
3235

3336
[null, null, null, null, 2, 1, 3]
3437

3538
</pre>
39+
3640
## Solutions
41+
3742
<!-- tabs:start -->
43+
3844
### **Python3**
45+
3946
```python
4047

4148
```
49+
4250
### **Java**
51+
4352
```java
4453

4554
```
55+
4656
### **TypeScript**
57+
4758
```ts
4859
class StackOfPlates {
4960
private cap: number;
@@ -96,8 +107,11 @@ class StackOfPlates {
96107
* var param_3 = obj.popAt(index)
97108
*/
98109
```
110+
99111
### **...**
112+
100113
```
101114
102115
```
116+
103117
<!-- tabs:end -->

lcci/04.09.BST Sequences/README.md

+15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# [面试题 04.09. 二叉搜索树序列](https://leetcode.cn/problems/bst-sequences-lcci)
2+
23
[English Version](/lcci/04.09.BST%20Sequences/README_EN.md)
4+
35
## 题目描述
6+
47
<!-- 这里写题目描述 -->
58
<p>从左向右遍历一个数组,通过不断将其中的元素插入树中可以逐步地生成一棵二叉搜索树。给定一个由不同节点组成的二叉树,输出所有可能生成此树的数组。</p>
69
<p><strong>示例:</strong><br>
@@ -15,21 +18,33 @@
1518
[2,3,1]
1619
]
1720
</pre>
21+
1822
## 解法
23+
1924
<!-- 这里可写通用的实现逻辑 -->
25+
2026
<!-- tabs:start -->
27+
2128
### **Python3**
29+
2230
<!-- 这里可写当前语言的特殊实现逻辑 -->
31+
2332
```python
2433

2534
```
35+
2636
### **Java**
37+
2738
<!-- 这里可写当前语言的特殊实现逻辑 -->
39+
2840
```java
2941

3042
```
43+
3144
### **...**
45+
3246
```
3347
3448
```
49+
3550
<!-- tabs:end -->

lcci/04.09.BST Sequences/README_EN.md

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# [04.09. BST Sequences](https://leetcode.cn/problems/bst-sequences-lcci)
2+
23
[中文文档](/lcci/04.09.BST%20Sequences/README.md)
4+
35
## Description
6+
47
<p>A binary search tree was created by traversing through an array from left to right and inserting each element. Given a binary search tree with distinct elements, print all possible arrays that could have led to this tree.</p>
58
<p><strong>Example:</strong><br />
69
Given the following tree:</p>
@@ -18,25 +21,34 @@ Given the following tree:</p>
1821

1922
[
2023

21-
[2,1,3],
24+
[2,1,3],
2225

23-
[2,3,1]
26+
[2,3,1]
2427

2528
]
2629

2730
</pre>
31+
2832
## Solutions
33+
2934
<!-- tabs:start -->
35+
3036
### **Python3**
37+
3138
```python
3239

3340
```
41+
3442
### **Java**
43+
3544
```java
3645

3746
```
47+
3848
### **...**
49+
3950
```
4051
4152
```
53+
4254
<!-- tabs:end -->

lcci/05.02.Bianry Number to String/README.md

+15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# [面试题 05.02. 二进制数转字符串](https://leetcode.cn/problems/bianry-number-to-string-lcci)
2+
23
[English Version](/lcci/05.02.Bianry%20Number%20to%20String/README_EN.md)
4+
35
## 题目描述
6+
47
<!-- 这里写题目描述 -->
58
<p>二进制数转字符串。给定一个介于0和1之间的实数(如0.72),类型为double,打印它的二进制表达式。如果该数字不在0和1之间,<strong>或者</strong>无法精确地用32位以内的二进制表示,则打印&ldquo;ERROR&rdquo;。</p>
69
<p><strong>示例1:</strong></p>
@@ -16,21 +19,33 @@
1619
<ol>
1720
<li>32位包括输出中的&quot;0.&quot;这两位。</li>
1821
</ol>
22+
1923
## 解法
24+
2025
<!-- 这里可写通用的实现逻辑 -->
26+
2127
<!-- tabs:start -->
28+
2229
### **Python3**
30+
2331
<!-- 这里可写当前语言的特殊实现逻辑 -->
32+
2433
```python
2534

2635
```
36+
2737
### **Java**
38+
2839
<!-- 这里可写当前语言的特殊实现逻辑 -->
40+
2941
```java
3042

3143
```
44+
3245
### **...**
46+
3347
```
3448
3549
```
50+
3651
<!-- tabs:end -->

lcci/05.02.Bianry Number to String/README_EN.md

+12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# [05.02. Bianry Number to String](https://leetcode.cn/problems/bianry-number-to-string-lcci)
2+
23
[中文文档](/lcci/05.02.Bianry%20Number%20to%20String/README.md)
4+
35
## Description
6+
47
<p>Given a real number between O and 1 (e.g., 0.72) that is passed in as a double, print the binary representation. If the number cannot be represented accurately in binary with at most 32 characters, print &quot;ERROR&quot;.</p>
58
<p><strong>Example1:</strong></p>
69
<pre>
@@ -24,18 +27,27 @@
2427
<ol>
2528
<li>This two charaters &quot;0.&quot; should be counted into 32 characters.</li>
2629
</ol>
30+
2731
## Solutions
32+
2833
<!-- tabs:start -->
34+
2935
### **Python3**
36+
3037
```python
3138

3239
```
40+
3341
### **Java**
42+
3443
```java
3544

3645
```
46+
3747
### **...**
48+
3849
```
3950
4051
```
52+
4153
<!-- tabs:end -->

lcci/05.03.Reverse Bits/README.md

+15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# [面试题 05.03. 翻转数位](https://leetcode.cn/problems/reverse-bits-lcci)
2+
23
[English Version](/lcci/05.03.Reverse%20Bits/README_EN.md)
4+
35
## 题目描述
6+
47
<!-- 这里写题目描述 -->
58
<p>给定一个32位整数 <code>num</code>,你可以将一个数位从0变为1。请编写一个程序,找出你能够获得的最长的一串1的长度。</p>
69
<p><strong>示例 1:</strong></p>
@@ -11,21 +14,33 @@
1114
<pre><strong>输入:</strong> <code>num</code> = 7(0111<sub>2</sub>)
1215
<strong>输出:</strong> 4
1316
</pre>
17+
1418
## 解法
19+
1520
<!-- 这里可写通用的实现逻辑 -->
21+
1622
<!-- tabs:start -->
23+
1724
### **Python3**
25+
1826
<!-- 这里可写当前语言的特殊实现逻辑 -->
27+
1928
```python
2029

2130
```
31+
2232
### **Java**
33+
2334
<!-- 这里可写当前语言的特殊实现逻辑 -->
35+
2436
```java
2537

2638
```
39+
2740
### **...**
41+
2842
```
2943
3044
```
45+
3146
<!-- tabs:end -->

lcci/05.03.Reverse Bits/README_EN.md

+12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# [05.03. Reverse Bits](https://leetcode.cn/problems/reverse-bits-lcci)
2+
23
[中文文档](/lcci/05.03.Reverse%20Bits/README.md)
4+
35
## Description
6+
47
<p>You have an integer and you can flip exactly one bit from a 0 to a 1. Write code to find the length of the longest sequence of 1s you could create.</p>
58
<p><strong>Example 1: </strong></p>
69
<pre>
@@ -18,18 +21,27 @@
1821
<strong>Output:</strong> 4
1922

2023
</pre>
24+
2125
## Solutions
26+
2227
<!-- tabs:start -->
28+
2329
### **Python3**
30+
2431
```python
2532

2633
```
34+
2735
### **Java**
36+
2837
```java
2938

3039
```
40+
3141
### **...**
42+
3243
```
3344
3445
```
46+
3547
<!-- tabs:end -->

0 commit comments

Comments
 (0)