Skip to content

Commit 85a0a76

Browse files
committed
docs: code format
1 parent e6906e4 commit 85a0a76

File tree

790 files changed

+1654
-3826
lines changed

Some content is hidden

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

790 files changed

+1654
-3826
lines changed

basic/searching/BinarySearch/README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@ int search(int left, int right) {
2525
### 模板 2
2626

2727
```java
28-
boolean check(int x) {}
28+
boolean
29+
check(int x) {
30+
}
2931

30-
int search(int left, int right) {
32+
int
33+
search(int left, int right) {
3134
while (left < right) {
3235
int mid = (left + right + 1) >> 1;
3336
if (check(mid)) {

basic/searching/BinarySearch/README_EN.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@ int search(int left, int right) {
2323
### Template 2
2424

2525
```java
26-
boolean check(int x) {}
26+
boolean
27+
check(int x) {
28+
}
2729

28-
int search(int left, int right) {
30+
int
31+
search(int left, int right) {
2932
while (left < right) {
3033
int mid = (left + right + 1) >> 1;
3134
if (check(mid)) {

basic/sorting/CountingSort/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
### **Java**
1818

1919
```java
20-
public static void sort(int[] nums, int min, int max) {
20+
public static void
21+
sort(int[] nums, int min, int max) {
2122
int[] c = new int[max - min + 1];
2223
for (int v : nums) {
2324
c[v - min]++;

basic/sorting/InsertionSort/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class InsertionSort {
2727
private static void insertionSort(int[] nums) {
2828
for (int i = 1, j, n = nums.length; i < n; ++i) {
2929
int num = nums[i];
30-
for (j = i - 1; j >=0 && nums[j] > num; --j) {
30+
for (j = i - 1; j >= 0 && nums[j] > num; --j) {
3131
nums[j + 1] = nums[j];
3232
}
3333
nums[j + 1] = num;

basic/sorting/QuickSort/README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,10 @@ public class Main {
121121
int i = left - 1, j = right + 1;
122122
int x = nums[(left + right) >> 1];
123123
while (i < j) {
124-
while (nums[++i] < x);
125-
while (nums[--j] > x);
124+
while (nums[++i] < x)
125+
;
126+
while (nums[--j] > x)
127+
;
126128
if (i < j) {
127129
int t = nums[i];
128130
nums[i] = nums[j];

basic/sorting/SelectionSort/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public class SelectionSort {
3737
System.out.println(Arrays.toString(nums));
3838
}
3939
}
40-
4140
```
4241

4342
### **JavaScript**

basic/sorting/ShellSort/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class ShellSort {
3636
}
3737

3838
public static void main(String[] args) {
39-
System.out.println(Arrays.toString(shellSort(new int[]{1, 2, 7, 9, 5, 8})));
39+
System.out.println(Arrays.toString(shellSort(new int[] {1, 2, 7, 9, 5, 8})));
4040
}
4141
}
4242
```

lcci/02.05.Sum Lists/README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ class Solution {
8080
ListNode dummy = new ListNode(-1);
8181
ListNode cur = dummy;
8282
while (l1 != null || l2 != null || carry != 0) {
83-
int s =
84-
(l1 == null ? 0 : l1.val) + (l2 == null ? 0 : l2.val) + carry;
83+
int s = (l1 == null ? 0 : l1.val) + (l2 == null ? 0 : l2.val) + carry;
8584
carry = s / 10;
8685
cur.next = new ListNode(s % 10);
8786
cur = cur.next;

lcci/02.05.Sum Lists/README_EN.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ class Solution {
7575
ListNode dummy = new ListNode(-1);
7676
ListNode cur = dummy;
7777
while (l1 != null || l2 != null || carry != 0) {
78-
int s =
79-
(l1 == null ? 0 : l1.val) + (l2 == null ? 0 : l2.val) + carry;
78+
int s = (l1 == null ? 0 : l1.val) + (l2 == null ? 0 : l2.val) + carry;
8079
carry = s / 10;
8180
cur.next = new ListNode(s % 10);
8281
cur = cur.next;

lcci/03.03.Stack of Plates/README.md

-30
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,45 @@
11
# [面试题 03.03. 堆盘子](https://leetcode.cn/problems/stack-of-plates-lcci)
2-
32
[English Version](/lcci/03.03.Stack%20of%20Plates/README_EN.md)
4-
53
## 题目描述
6-
74
<!-- 这里写题目描述 -->
85
<p>堆盘子。设想有一堆盘子,堆太高可能会倒下来。因此,在现实生活中,盘子堆到一定高度时,我们就会另外堆一堆盘子。请实现数据结构<code>SetOfStacks</code>,模拟这种行为。<code>SetOfStacks</code>应该由多个栈组成,并且在前一个栈填满时新建一个栈。此外,<code>SetOfStacks.push()</code>和<code>SetOfStacks.pop()</code>应该与普通栈的操作方法相同(也就是说,pop()返回的值,应该跟只有一个栈时的情况一样)。 进阶:实现一个<code>popAt(int index)</code>方法,根据指定的子栈,执行pop操作。</p>
9-
106
<p>当某个栈为空时,应当删除该栈。当栈中没有元素或不存在该栈时,<code>pop</code>,<code>popAt</code>&nbsp;应返回 -1.</p>
11-
127
<p><strong>示例1:</strong></p>
13-
148
<pre><strong> 输入</strong>:
159
[&quot;StackOfPlates&quot;, &quot;push&quot;, &quot;push&quot;, &quot;popAt&quot;, &quot;pop&quot;, &quot;pop&quot;]
1610
[[1], [1], [2], [1], [], []]
1711
<strong> 输出</strong>:
1812
[null, null, null, 2, 1, -1]
1913
</pre>
20-
2114
<p><strong>示例2:</strong></p>
22-
2315
<pre><strong> 输入</strong>:
2416
[&quot;StackOfPlates&quot;, &quot;push&quot;, &quot;push&quot;, &quot;push&quot;, &quot;popAt&quot;, &quot;popAt&quot;, &quot;popAt&quot;]
2517
[[2], [1], [2], [3], [0], [0], [0]]
2618
<strong> 输出</strong>:
2719
[null, null, null, null, 2, 1, 3]
2820
</pre>
29-
3021
## 解法
31-
3222
<!-- 这里可写通用的实现逻辑 -->
33-
3423
<!-- tabs:start -->
35-
3624
### **Python3**
37-
3825
<!-- 这里可写当前语言的特殊实现逻辑 -->
39-
4026
```python
4127

42-
4328
```
44-
4529
### **Java**
46-
4730
<!-- 这里可写当前语言的特殊实现逻辑 -->
48-
4931
```java
5032

51-
5233
```
53-
5434
### **TypeScript**
55-
5635
```ts
5736
class StackOfPlates {
5837
private cap: number;
5938
private stacks: number[][];
60-
6139
constructor(cap: number) {
6240
this.cap = cap;
6341
this.stacks = [];
6442
}
65-
6643
push(val: number): void {
6744
if (this.cap === 0) {
6845
return;
@@ -75,7 +52,6 @@ class StackOfPlates {
7552
stack.push(val);
7653
}
7754
}
78-
7955
pop(): number {
8056
const n = this.stacks.length;
8157
if (n === 0) {
@@ -88,7 +64,6 @@ class StackOfPlates {
8864
}
8965
return res;
9066
}
91-
9267
popAt(index: number): number {
9368
if (index >= this.stacks.length) {
9469
return -1;
@@ -101,7 +76,6 @@ class StackOfPlates {
10176
return res;
10277
}
10378
}
104-
10579
/**
10680
* Your StackOfPlates object will be instantiated and called as such:
10781
* var obj = new StackOfPlates(cap)
@@ -110,12 +84,8 @@ class StackOfPlates {
11084
* var param_3 = obj.popAt(index)
11185
*/
11286
```
113-
11487
### **...**
115-
11688
```
11789
118-
11990
```
120-
12191
<!-- tabs:end -->
-53
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,57 @@
11
# [03.03. Stack of Plates](https://leetcode.cn/problems/stack-of-plates-lcci)
2-
32
[中文文档](/lcci/03.03.Stack%20of%20Plates/README.md)
4-
53
## Description
6-
74
<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>
8-
95
<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>
10-
116
<p><strong>Example1:</strong></p>
12-
137
<pre>
148

15-
16-
179
<strong> Input</strong>:
1810

19-
20-
2111
[&quot;StackOfPlates&quot;, &quot;push&quot;, &quot;push&quot;, &quot;popAt&quot;, &quot;pop&quot;, &quot;pop&quot;]
2212

23-
24-
2513
[[1], [1], [2], [1], [], []]
2614

27-
28-
2915
<strong> Output</strong>:
3016

31-
32-
3317
[null, null, null, 2, 1, -1]
3418

35-
36-
3719
<strong> Explanation</strong>:
3820

39-
40-
4121
</pre>
42-
4322
<p><strong>Example2:</strong></p>
44-
4523
<pre>
4624

47-
48-
4925
<strong> Input</strong>:
5026

51-
52-
5327
[&quot;StackOfPlates&quot;, &quot;push&quot;, &quot;push&quot;, &quot;push&quot;, &quot;popAt&quot;, &quot;popAt&quot;, &quot;popAt&quot;]
5428

55-
56-
5729
[[2], [1], [2], [3], [0], [0], [0]]
5830

59-
60-
6131
<strong> Output</strong>:
6232

63-
64-
6533
[null, null, null, null, 2, 1, 3]
6634

67-
68-
6935
</pre>
70-
7136
## Solutions
72-
7337
<!-- tabs:start -->
74-
7538
### **Python3**
76-
7739
```python
7840

79-
8041
```
81-
8242
### **Java**
83-
8443
```java
8544

86-
8745
```
88-
8946
### **TypeScript**
90-
9147
```ts
9248
class StackOfPlates {
9349
private cap: number;
9450
private stacks: number[][];
95-
9651
constructor(cap: number) {
9752
this.cap = cap;
9853
this.stacks = [];
9954
}
100-
10155
push(val: number): void {
10256
if (this.cap === 0) {
10357
return;
@@ -110,7 +64,6 @@ class StackOfPlates {
11064
stack.push(val);
11165
}
11266
}
113-
11467
pop(): number {
11568
const n = this.stacks.length;
11669
if (n === 0) {
@@ -123,7 +76,6 @@ class StackOfPlates {
12376
}
12477
return res;
12578
}
126-
12779
popAt(index: number): number {
12880
if (index >= this.stacks.length) {
12981
return -1;
@@ -136,7 +88,6 @@ class StackOfPlates {
13688
return res;
13789
}
13890
}
139-
14091
/**
14192
* Your StackOfPlates object will be instantiated and called as such:
14293
* var obj = new StackOfPlates(cap)
@@ -145,12 +96,8 @@ class StackOfPlates {
14596
* var param_3 = obj.popAt(index)
14697
*/
14798
```
148-
14999
### **...**
150-
151100
```
152101
153-
154102
```
155-
156103
<!-- tabs:end -->

lcci/03.06.Animal Shelter/README.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,18 @@ class AnimalShelf {
103103
}
104104

105105
public int[] dequeueAny() {
106-
return dogs.isEmpty() ? dequeueCat() : (cats.isEmpty() ? dequeueDog() : (dogs.peek() < cats.peek() ? dequeueDog() : dequeueCat()));
106+
return dogs.isEmpty()
107+
? dequeueCat()
108+
: (cats.isEmpty() ? dequeueDog()
109+
: (dogs.peek() < cats.peek() ? dequeueDog() : dequeueCat()));
107110
}
108111

109112
public int[] dequeueDog() {
110-
return dogs.isEmpty() ? new int[]{-1, -1} : new int[]{dogs.poll(), 1};
113+
return dogs.isEmpty() ? new int[] {-1, -1} : new int[] {dogs.poll(), 1};
111114
}
112115

113116
public int[] dequeueCat() {
114-
return cats.isEmpty() ? new int[]{-1, -1} : new int[]{cats.poll(), 0};
117+
return cats.isEmpty() ? new int[] {-1, -1} : new int[] {cats.poll(), 0};
115118
}
116119
}
117120

lcci/03.06.Animal Shelter/README_EN.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,18 @@ class AnimalShelf {
108108
}
109109

110110
public int[] dequeueAny() {
111-
return dogs.isEmpty() ? dequeueCat() : (cats.isEmpty() ? dequeueDog() : (dogs.peek() < cats.peek() ? dequeueDog() : dequeueCat()));
111+
return dogs.isEmpty()
112+
? dequeueCat()
113+
: (cats.isEmpty() ? dequeueDog()
114+
: (dogs.peek() < cats.peek() ? dequeueDog() : dequeueCat()));
112115
}
113116

114117
public int[] dequeueDog() {
115-
return dogs.isEmpty() ? new int[]{-1, -1} : new int[]{dogs.poll(), 1};
118+
return dogs.isEmpty() ? new int[] {-1, -1} : new int[] {dogs.poll(), 1};
116119
}
117120

118121
public int[] dequeueCat() {
119-
return cats.isEmpty() ? new int[]{-1, -1} : new int[]{cats.poll(), 0};
122+
return cats.isEmpty() ? new int[] {-1, -1} : new int[] {cats.poll(), 0};
120123
}
121124
}
122125

0 commit comments

Comments
 (0)