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

[pull] main from itcharge:main #137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
pull merged 3 commits into AlgorithmAndLeetCode:main from itcharge:main
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
120 changes: 59 additions & 61 deletions Contents/00.Introduction/01.Data-Structures-Algorithms.md
View file Open in desktop

Large diffs are not rendered by default.

121 changes: 58 additions & 63 deletions Contents/00.Introduction/02.Algorithm-Complexity.md
View file Open in desktop

Large diffs are not rendered by default.

128 changes: 78 additions & 50 deletions Contents/00.Introduction/03.LeetCode-Guide.md
View file Open in desktop

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions Contents/01.Array/01.Array-Basic/01.Array-Basic.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ int[][] arr = new int[3][]{ {1,2,3}, {4,5}, {6,7,8,9}};

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

```Python
```python
arr = ['python', 'java', ['asp', 'php'], 'c']
```

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

示例代码如下:

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

示例代码如下:

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

示例代码如下:

```Python
```python
arr = [0, 5, 2, 3, 7, 1, 6]
val = 4
arr.append(val)
Expand All @@ -135,7 +135,7 @@ print(arr)

示例代码如下:

```Python
```python
arr = [0, 5, 2, 3, 7, 1, 6]
i, val = 2, 4
arr.insert(i, val)
Expand All @@ -150,7 +150,7 @@ print(arr)

示例代码如下:

```Python
```python
def change(nums, i, val):
if 0 <= i <= len(nums) - 1:
nums[i] = val
Expand All @@ -173,7 +173,7 @@ print(arr)

示例代码如下:

```Python
```python
arr = [0, 5, 2, 3, 7, 1, 6]
arr.pop()
print(arr)
Expand All @@ -198,7 +198,7 @@ print(arr)

示例代码如下:

```Python
```python
arr = [0, 5, 2, 3, 7, 1, 6]
i = 3
arr.remove(5)
Expand Down
2 changes: 1 addition & 1 deletion Contents/01.Array/02.Array-Sort/01.Array-Bubble-Sort.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

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

```Python
```python
class Solution:
def bubbleSort(self, arr):
# 第 i 趟排序
Expand Down
2 changes: 1 addition & 1 deletion Contents/01.Array/02.Array-Sort/02.Array-Selection-Sort.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

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

```Python
```python
class Solution:
def selectionSort(self, arr):
for i in range(len(arr) - 1):
Expand Down
2 changes: 1 addition & 1 deletion Contents/01.Array/02.Array-Sort/03.Array-Insertion-Sort.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

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

```Python
```python
class Solution:
def insertionSort(self, arr):
# 遍历无序序列
Expand Down
2 changes: 1 addition & 1 deletion Contents/01.Array/02.Array-Sort/04.Array-Shell-Sort.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

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

```Python
```python
class Solution:
def shellSort(self, arr):
size = len(arr)
Expand Down
2 changes: 1 addition & 1 deletion Contents/01.Array/02.Array-Sort/05.Array-Merge-Sort.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

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

```Python
```python
class Solution:
def merge(self, left_arr, right_arr): # 归并过程
arr = []
Expand Down
2 changes: 1 addition & 1 deletion Contents/01.Array/02.Array-Sort/06.Array-Quick-Sort.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@

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

```Python
```python
import random

class Solution:
Expand Down
2 changes: 1 addition & 1 deletion Contents/01.Array/02.Array-Sort/07.Array-Heap-Sort.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@

## 6. 堆排序代码实现

```Python
```python
class Solution:
# 调整为大顶堆
def heapify(self, arr: [int], index: int, end: int):
Expand Down
2 changes: 1 addition & 1 deletion Contents/01.Array/02.Array-Sort/08.Array-Counting-Sort.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

## 5. 计数排序代码实现

```Python
```python
class Solution:
def countingSort(self, arr):
# 计算待排序序列中最大值元素 arr_max 和最小值元素 arr_min
Expand Down
2 changes: 1 addition & 1 deletion Contents/01.Array/02.Array-Sort/09.Array-Bucket-Sort.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

## 5. 桶排序代码实现

```Python
```python
class Solution:
def insertionSort(self, arr):
# 遍历无序序列
Expand Down
2 changes: 1 addition & 1 deletion Contents/01.Array/02.Array-Sort/10.Array-Radix-Sort.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

## 5. 基数排序代码实现

```Python
```python
class Solution:
def radixSort(self, arr):
# 桶的大小为所有元素的最大位数
Expand Down
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

**示例**:

```Python
```python
输入: nums = [-1,0,3,5,9,12], target = 9
输出: 4
解释: 9 出现在 nums 中并且下标为 4
Expand All @@ -75,7 +75,7 @@

#### 思路 1:代码

```Python
```python
class Solution:
def search(self, nums: List[int], target: int) -> int:
left, right = 0, len(nums) - 1
Expand Down Expand Up @@ -147,7 +147,7 @@ class Solution:

可以在返回的时候需要增加一层判断,判断 `left` 所指向位置是否等于目标元素,如果是的话就返回 `left`,如果不是的话返回 `-1`。即:

````Python
````python
# ...
while left < right:
# ...
Expand Down Expand Up @@ -187,7 +187,7 @@ class Solution:

#### 代码:

```Python
```python
class Solution:
def search(self, nums: List[int], target: int) -> int:
left, right = 0, len(nums) - 1
Expand Down Expand Up @@ -229,7 +229,7 @@ class Solution:

#### 第一种代码:

```Python
```python
class Solution:
def search(self, nums: List[int], target: int) -> int:
left, right = 0, len(nums) - 1
Expand All @@ -250,7 +250,7 @@ class Solution:

#### 第二种代码:

```Python
```python
class Solution:
def search(self, nums: List[int], target: int) -> int:
left, right = 0, len(nums) - 1
Expand Down
28 changes: 14 additions & 14 deletions Contents/01.Array/04.Array-Two-Pointers/01.Array-Two-Pointers.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

### 2.2 对撞指针伪代码模板

```Python
```python
left, right = 0, len(nums) - 1

while left < right:
Expand Down Expand Up @@ -61,7 +61,7 @@ return 没找到 或 找到对应值

**示例**:

```Python
```python
输入:numbers = [2,7,11,15], target = 9
输出:[1,2]
解释:2 与 7 之和等于目标数 9 。因此 index1 = 1, index2 = 2 。返回 [1, 2] 。
Expand All @@ -76,7 +76,7 @@ return 没找到 或 找到对应值

这道题如果暴力遍历数组,从中找到相加之和等于 `target` 的两个数,时间复杂度为 $O(n^2),ドル可以尝试一下。

```Python
```python
class Solution:
def twoSum(self, numbers: List[int], target: int) -> List[int]:
size = len(numbers)
Expand All @@ -103,7 +103,7 @@ class Solution:

##### 思路 1:代码

```Python
```python
class Solution:
def twoSum(self, numbers: List[int], target: int) -> List[int]:
left = 0
Expand Down Expand Up @@ -144,7 +144,7 @@ class Solution:

**示例**:

```Python
```python
输入: "A man, a plan, a canal: Panama"
输出:true
解释:"amanaplanacanalpanama" 是回文串。
Expand All @@ -168,7 +168,7 @@ class Solution:

##### 思路 1:代码

```Python
```python
class Solution:
def isPalindrome(self, s: str) -> bool:
left = 0
Expand Down Expand Up @@ -217,7 +217,7 @@ class Solution:

![](https://aliyun-lc-upload.oss-cn-hangzhou.aliyuncs.com/aliyun-lc-upload/uploads/2018/07/25/question_11.jpg)

```Python
```python
输入:[1,8,6,2,5,4,8,3,7]
输出:49
解释:图中垂直线代表输入数组 [1,8,6,2,5,4,8,3,7]。在此情况下,容器能够容纳水(表示为蓝色部分)的最大值为 49。
Expand All @@ -240,7 +240,7 @@ class Solution:

##### 思路 1:代码

```Python
```python
class Solution:
def maxArea(self, height: List[int]) -> int:
left = 0
Expand Down Expand Up @@ -273,7 +273,7 @@ class Solution:

### 3.2 快慢指针伪代码模板

```Python
```python
slow = 0
fast = 1
while 没有遍历完:
Expand Down Expand Up @@ -307,7 +307,7 @@ return 合适的值

**示例**:

```Python
```python
输入:nums = [1,1,2]
输出:2, nums = [1,2,_]
解释:函数应该返回新的长度 2 ,并且原数组 nums 的前两个元素被修改为 1, 2 。不需要考虑数组中超出新长度后面的元素。
Expand Down Expand Up @@ -336,7 +336,7 @@ return 合适的值

##### 思路 1:代码

```Python
```python
class Solution:
def removeDuplicates(self, nums: List[int]) -> int:
if len(nums) <= 1:
Expand Down Expand Up @@ -372,7 +372,7 @@ class Solution:

### 4.2 分离双指针伪代码模板

```Python
```python
left_1 = 0
left_2 = 0

Expand Down Expand Up @@ -411,7 +411,7 @@ while left_1 < len(nums1) and left_2 < len(nums2):

**示例**:

```Python
```python
输入:nums1 = [1,2,2,1], nums2 = [2,2]
输出:[2]
示例 2:
Expand All @@ -434,7 +434,7 @@ while left_1 < len(nums1) and left_2 < len(nums2):

##### 思路 1:代码

```Python
```python
class Solution:
def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]:
nums1.sort()
Expand Down
Loading

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