Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 963fa66

Browse files
committed
更新代码格式
1 parent ee4ffcc commit 963fa66

File tree

888 files changed

+2018
-2018
lines changed

Some content is hidden

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

888 files changed

+2018
-2018
lines changed

‎Contents/00.Introduction/02.Algorithm-Complexity.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
下面通过一个具体例子来说明一下如何计算时间复杂度。
4545

46-
```Python
46+
```python
4747
def algorithm(n):
4848
fact = 1
4949
for i in range(1, n + 1):
@@ -120,7 +120,7 @@ $\Theta$ 符号渐进地给出了一个函数的上界和下界,如果我们
120120

121121
$O(1)$ 只是常数阶时间复杂度的一种表示方式,并不是指只执行了一行代码。只要代码的执行时间不随着问题规模 n 的增大而增长,这样的算法时间复杂度都记为 $O(1)$。
122122

123-
```Python
123+
```python
124124
def algorithm(n):
125125
a = 1
126126
b = 2
@@ -134,7 +134,7 @@ def algorithm(n):
134134

135135
一般含有非嵌套循环,且单层循环下的语句执行次数为 n 的算法涉及线性时间复杂度。这类算法随着问题规模 n 的增大,对应计算次数呈线性增长。
136136

137-
```Python
137+
```python
138138
def algorithm(n):
139139
sum = 0
140140
for i in range(n):
@@ -149,7 +149,7 @@ def algorithm(n):
149149

150150
一般含有双层嵌套,且每层循环下的语句执行次数为 n 的算法涉及平方时间复杂度。这类算法随着问题规模 n 的增大,对应计算次数呈平方关系增长。
151151

152-
```Python
152+
```python
153153
def algorithm(n):
154154
res = 0
155155
for i in range(n):
@@ -164,7 +164,7 @@ def algorithm(n):
164164

165165
阶乘时间复杂度一般出现在与「全排列」、「旅行商问题暴力解法」相关的算法中。这类算法随着问题规模 n 的增大,对应计算次数呈阶乘关系增长。
166166

167-
```Python
167+
```python
168168
def permutations(arr, start, end):
169169
if start == end:
170170
print(arr)
@@ -182,7 +182,7 @@ def permutations(arr, start, end):
182182

183183
对数时间复杂度一般出现在「二分查找」、「分治」这种一分为二的算法中。这类算法随着问题规模 n 的增大,对应的计算次数呈对数关系增长。
184184

185-
```Python
185+
```python
186186
def algorithm(n):
187187
cnt = 1
188188
while cnt < n:
@@ -197,7 +197,7 @@ def algorithm(n):
197197

198198
线性对数一般出现在排序算法中,例如「快速排序」、「归并排序」、「堆排序」等。这类算法随着问题规模 n 的增大,对应的计算次数呈线性对数关系增长。
199199

200-
```Python
200+
```python
201201
def algorithm(n):
202202
cnt = 1
203203
res = 0
@@ -225,7 +225,7 @@ def algorithm(n):
225225

226226
我们通过一个例子来分析下最佳、最坏、最差时间复杂度。
227227

228-
```Python
228+
```python
229229
def find(nums, val):
230230
pos = -1
231231
for i in range(n):
@@ -263,7 +263,7 @@ def find(nums, val):
263263

264264
#### 3.1.1 常数 O(1)
265265

266-
```Python
266+
```python
267267
def algorithm(n):
268268
a = 1
269269
b = 2
@@ -275,7 +275,7 @@ def algorithm(n):
275275

276276
#### 3.1.2 线性 O(n)
277277

278-
```Python
278+
```python
279279
def algorithm(n):
280280
if n <= 0:
281281
return 1

‎Contents/00.Introduction/03.LeetCode-Guide.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ LeetCode 提供了题目的搜索过滤功能。可以筛选相关题单、不
114114

115115
1. 思路一:暴力搜索
116116

117-
```Python
117+
```python
118118
class Solution:
119119
def twoSum(self, nums: List[int], target: int) -> List[int]:
120120
size = len(nums)
@@ -127,7 +127,7 @@ class Solution:
127127

128128
2. 思路二:哈希表
129129

130-
```Python
130+
```python
131131
class Solution:
132132
def twoSum(self, nums: List[int], target: int) -> List[int]:
133133
size = len(nums)

‎Contents/01.Array/01.Array-Basic/01.Array-Basic.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ int[][] arr = new int[3][]{ {1,2,3}, {4,5}, {6,7,8,9}};
6666

6767
原生 `Python` 中其实没有数组的概念,而是使用了类似 `Java` 中的 `ArrayList` 容器类数据结构,叫做列表。通常我们把列表来作为 `Python` 中的数组使用。`Python` 中列表存储的数据类型可以不一致,数组长度也可以不一致。例如:
6868

69-
```Python
69+
```python
7070
arr = ['python', 'java', ['asp', 'php'], 'c']
7171
```
7272

@@ -80,7 +80,7 @@ arr = ['python', 'java', ['asp', 'php'], 'c']
8080

8181
示例代码如下:
8282

83-
```Python
83+
```python
8484
# 从数组 nums 中读取下标为 i 的数据元素值
8585
def value(nums, i):
8686
if 0 <= i <= len(nums) - 1:
@@ -96,7 +96,7 @@ value(arr, 3)
9696

9797
示例代码如下:
9898

99-
```Python
99+
```python
100100
# 从数组 nums 中查找元素值为 val 的数据元素第一次出现的位置
101101
def find(nums, val):
102102
for i in range(len(nums)):
@@ -120,7 +120,7 @@ print(find(arr, 5))
120120

121121
示例代码如下:
122122

123-
```Python
123+
```python
124124
arr = [0, 5, 2, 3, 7, 1, 6]
125125
val = 4
126126
arr.append(val)
@@ -135,7 +135,7 @@ print(arr)
135135

136136
示例代码如下:
137137

138-
```Python
138+
```python
139139
arr = [0, 5, 2, 3, 7, 1, 6]
140140
i, val = 2, 4
141141
arr.insert(i, val)
@@ -150,7 +150,7 @@ print(arr)
150150

151151
示例代码如下:
152152

153-
```Python
153+
```python
154154
def change(nums, i, val):
155155
if 0 <= i <= len(nums) - 1:
156156
nums[i] = val
@@ -173,7 +173,7 @@ print(arr)
173173

174174
示例代码如下:
175175

176-
```Python
176+
```python
177177
arr = [0, 5, 2, 3, 7, 1, 6]
178178
arr.pop()
179179
print(arr)
@@ -198,7 +198,7 @@ print(arr)
198198

199199
示例代码如下:
200200

201-
```Python
201+
```python
202202
arr = [0, 5, 2, 3, 7, 1, 6]
203203
i = 3
204204
arr.remove(5)

‎Contents/01.Array/02.Array-Sort/01.Array-Bubble-Sort.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949

5050
## 5. 冒泡排序代码实现
5151

52-
```Python
52+
```python
5353
class Solution:
5454
def bubbleSort(self, arr):
5555
# 第 i 趟排序

‎Contents/01.Array/02.Array-Sort/02.Array-Selection-Sort.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
## 5. 选择排序代码实现
4646

47-
```Python
47+
```python
4848
class Solution:
4949
def selectionSort(self, arr):
5050
for i in range(len(arr) - 1):

‎Contents/01.Array/02.Array-Sort/03.Array-Insertion-Sort.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949

5050
## 5. 插入排序代码实现
5151

52-
```Python
52+
```python
5353
class Solution:
5454
def insertionSort(self, arr):
5555
# 遍历无序序列

‎Contents/01.Array/02.Array-Sort/04.Array-Shell-Sort.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
## 5. 希尔排序代码实现
2929

30-
```Python
30+
```python
3131
class Solution:
3232
def shellSort(self, arr):
3333
size = len(arr)

‎Contents/01.Array/02.Array-Sort/05.Array-Merge-Sort.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
## 5. 归并排序代码实现
4343

44-
```Python
44+
```python
4545
class Solution:
4646
def merge(self, left_arr, right_arr): # 归并过程
4747
arr = []

‎Contents/01.Array/02.Array-Sort/06.Array-Quick-Sort.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565

6666
## 5. 快速排序代码实现
6767

68-
```Python
68+
```python
6969
import random
7070

7171
class Solution:

‎Contents/01.Array/02.Array-Sort/07.Array-Heap-Sort.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383

8484
## 6. 堆排序代码实现
8585

86-
```Python
86+
```python
8787
class Solution:
8888
# 调整为大顶堆
8989
def heapify(self, arr: [int], index: int, end: int):

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /