Skip to content
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
  •  
  •  
  •  
26 changes: 13 additions & 13 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ appearance, race, religion, or sexual identity and orientation.
Examples of behavior that contributes to creating a positive environment
include:

- Using welcoming and inclusive language
- Being respectful of differing viewpoints and experiences
- Gracefully accepting constructive criticism
- Focusing on what is best for the community
- Showing empathy towards other community members
- Using welcoming and inclusive language
- Being respectful of differing viewpoints and experiences
- Gracefully accepting constructive criticism
- Focusing on what is best for the community
- Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

- The use of sexualized language or imagery and unwelcome sexual attention or
advances
- Trolling, insulting/derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others' private information, such as a physical or electronic
address, without explicit permission
- Other conduct which could reasonably be considered inappropriate in a
professional setting
- The use of sexualized language or imagery and unwelcome sexual attention or
advances
- Trolling, insulting/derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others' private information, such as a physical or electronic
address, without explicit permission
- Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
- [乘积小于 K 的子数组](/solution/0700-0799/0713.Subarray%20Product%20Less%20Than%20K/README.md) - `双指针`
- [位 1 的个数](/solution/0100-0199/0191.Number%20of%201%20Bits/README.md) - `位运算``lowbit`
- [合并区间](/solution/0000-0099/0056.Merge%20Intervals/README.md) - `区间合并`
<!-- 排序算法、待补充 -->
<!-- 排序算法、待补充 -->

### 2. 数据结构

Expand Down
242 changes: 121 additions & 121 deletions README_EN.md

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions basic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

## 排序算法

- [冒泡排序](/basic/sorting/BubbleSort/README.md)
- [插入排序](/basic/sorting/InsertionSort/README.md)
- [希尔排序](/basic/sorting/ShellSort/README.md)
- [选择排序](/basic/sorting/SelectionSort/README.md)
- [归并排序](/basic/sorting/MergeSort/README.md)
- [快速排序](/basic/sorting/QuickSort/README.md)
- [堆排序](/basic/sorting/HeapSort/README.md)
- [计数排序](/basic/sorting/CountingSort/README.md)
- [冒泡排序](/basic/sorting/BubbleSort/README.md)
- [插入排序](/basic/sorting/InsertionSort/README.md)
- [希尔排序](/basic/sorting/ShellSort/README.md)
- [选择排序](/basic/sorting/SelectionSort/README.md)
- [归并排序](/basic/sorting/MergeSort/README.md)
- [快速排序](/basic/sorting/QuickSort/README.md)
- [堆排序](/basic/sorting/HeapSort/README.md)
- [计数排序](/basic/sorting/CountingSort/README.md)

## 查找算法

- [二分查找](/basic/searching/BinarySearch/README.md)
- [二分查找](/basic/searching/BinarySearch/README.md)

## 版权

Expand Down
18 changes: 9 additions & 9 deletions basic/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

## Sorting

- [Bubble Sort](/basic/sorting/BubbleSort/README.md)
- [Insertion Sort](/basic/sorting/InsertionSort/README.md)
- [Shell Sort](/basic/sorting/ShellSort/README.md)
- [Selection Sort](/basic/sorting/SelectionSort/README.md)
- [Merge Sort](/basic/sorting/MergeSort/README.md)
- [Quick Sort](/basic/sorting/QuickSort/README.md)
- [Heap Sort](/basic/sorting/HeapSort/README.md)
- [Counting Sort](/basic/sorting/CountingSort/README.md)
- [Bubble Sort](/basic/sorting/BubbleSort/README.md)
- [Insertion Sort](/basic/sorting/InsertionSort/README.md)
- [Shell Sort](/basic/sorting/ShellSort/README.md)
- [Selection Sort](/basic/sorting/SelectionSort/README.md)
- [Merge Sort](/basic/sorting/MergeSort/README.md)
- [Quick Sort](/basic/sorting/QuickSort/README.md)
- [Heap Sort](/basic/sorting/HeapSort/README.md)
- [Counting Sort](/basic/sorting/CountingSort/README.md)

## Searching

- [Binary Search](/basic/searching/BinarySearch/README.md)
- [Binary Search](/basic/searching/BinarySearch/README.md)

## Copyright

Expand Down
10 changes: 5 additions & 5 deletions basic/searching/BinarySearch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ int search(int left, int right) {

## 例题

- [在排序数组中查找元素的第一个和最后一个位置](/solution/0000-0099/0034.Find%20First%20and%20Last%20Position%20of%20Element%20in%20Sorted%20Array/README.md)
- [x 的平方根](/solution/0000-0099/0069.Sqrt%28x%29/README.md)
- [寻找峰值](/solution/0100-0199/0162.Find%20Peak%20Element/README.md)
- [第一个错误的版本](/solution/0200-0299/0278.First%20Bad%20Version/README.md)
- [不动点](/solution/1000-1099/1064.Fixed%20Point/README.md)
- [在排序数组中查找元素的第一个和最后一个位置](/solution/0000-0099/0034.Find%20First%20and%20Last%20Position%20of%20Element%20in%20Sorted%20Array/README.md)
- [x 的平方根](/solution/0000-0099/0069.Sqrt%28x%29/README.md)
- [寻找峰值](/solution/0100-0199/0162.Find%20Peak%20Element/README.md)
- [第一个错误的版本](/solution/0200-0299/0278.First%20Bad%20Version/README.md)
- [不动点](/solution/1000-1099/1064.Fixed%20Point/README.md)
10 changes: 5 additions & 5 deletions basic/searching/BinarySearch/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ Note that the advantage of these two templates is that they always keep the answ

## Examples

- [Find First and Last Position of Element in Sorted Array](/solution/0000-0099/0034.Find%20First%20and%20Last%20Position%20of%20Element%20in%20Sorted%20Array/README_EN.md)
- [Sqrt(x)](/solution/0000-0099/0069.Sqrt%28x%29/README_EN.md)
- [Find Peak Element](/solution/0100-0199/0162.Find%20Peak%20Element/README_EN.md)
- [First Bad Version](/solution/0200-0299/0278.First%20Bad%20Version/README_EN.md)
- [Fixed Point](/solution/1000-1099/1064.Fixed%20Point/README_EN.md)
- [Find First and Last Position of Element in Sorted Array](/solution/0000-0099/0034.Find%20First%20and%20Last%20Position%20of%20Element%20in%20Sorted%20Array/README_EN.md)
- [Sqrt(x)](/solution/0000-0099/0069.Sqrt%28x%29/README_EN.md)
- [Find Peak Element](/solution/0100-0199/0162.Find%20Peak%20Element/README_EN.md)
- [First Bad Version](/solution/0200-0299/0278.First%20Bad%20Version/README_EN.md)
- [Fixed Point](/solution/1000-1099/1064.Fixed%20Point/README_EN.md)
14 changes: 7 additions & 7 deletions basic/sorting/CountingSort/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

算法描述:

- 给定原数组中元素值的范围 `[min, max]`
- 创建一个新数组 `c` ,其长度是 `max-min+1`,其元素默认值都是 `0`
- 遍历原数组中的元素,以原数组中的元素作为 `c` 数组的索引,以原数组中的元素出现次数作为 `c` 数组的元素值。
- 创建结果数组 `r`,起始索引 `i`
- 遍历数组 `c`,找出其中元素大于 `0` 的元素,将其对应的索引作为元素值填充到 `r` 数组中,每处理一次,`c` 中的元素值减 `1`,直到该元素值不大于 `0`,依次处理 `c` 中剩下的元素
- 给定原数组中元素值的范围 `[min, max]`
- 创建一个新数组 `c` ,其长度是 `max-min+1`,其元素默认值都是 `0`
- 遍历原数组中的元素,以原数组中的元素作为 `c` 数组的索引,以原数组中的元素出现次数作为 `c` 数组的元素值。
- 创建结果数组 `r`,起始索引 `i`
- 遍历数组 `c`,找出其中元素大于 `0` 的元素,将其对应的索引作为元素值填充到 `r` 数组中,每处理一次,`c` 中的元素值减 `1`,直到该元素值不大于 `0`,依次处理 `c` 中剩下的元素

## 算法分析

- 时间复杂度 $O(n+k)$, 其中 $n$ 为排序数组长度,而 $k$ 为排序数组中数值的取值范围,当 $k\lt n$ 时,时间复杂度为 $O(n)$。
- 空间复杂度 $O(n+k)$, 其中 $n$ 为排序数组长度,而 $k$ 为排序数组中数值的取值范围,当 $k\lt n$ 时,空间复杂度为 $O(n)$。
- 时间复杂度 $O(n+k)$, 其中 $n$ 为排序数组长度,而 $k$ 为排序数组中数值的取值范围,当 $k\lt n$ 时,时间复杂度为 $O(n)$。
- 空间复杂度 $O(n+k)$, 其中 $n$ 为排序数组长度,而 $k$ 为排序数组中数值的取值范围,当 $k\lt n$ 时,空间复杂度为 $O(n)$。
4 changes: 2 additions & 2 deletions basic/sorting/HeapSort/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ for (int i = n / 2; i > 0; --i) {

**数据范围**

- 1 ≤ m ≤ n ≤ 10^5
- 1 ≤ 数列中元素 ≤ 10^9
- 1 ≤ m ≤ n ≤ 10^5
- 1 ≤ 数列中元素 ≤ 10^9

**输入样例:**

Expand Down
4 changes: 2 additions & 2 deletions basic/sorting/InsertionSort/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

与冒泡排序对比:

- 在冒泡排序中,经过每一轮的排序处理后,数组后端的数是排好序的。
- 在插入排序中,经过每一轮的排序处理后,数组前端的数是排好序的。
- 在冒泡排序中,经过每一轮的排序处理后,数组后端的数是排好序的。
- 在插入排序中,经过每一轮的排序处理后,数组前端的数是排好序的。

## 代码示例

Expand Down
8 changes: 4 additions & 4 deletions basic/sorting/ShellSort/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

希尔排序,也被称为递减增量排序,是简单插入排序的一种改进版本。

- 在插入排序中,如果待排序列中的某个元素,距离有序数列中待插入位置非常远,就需要比较很多次才可以到达插入位置,这是因为待插入元素局部非常无序,比如说`[2, 3, 4, 5, 6, 7, 8, 1, ...]`,我们要插入 1,就必须将 1 和前面的 2-8 每个值都比较一下,就是因为 1 附近非常无序,想象一下,如果待插入元素附近比较有序,那么在进行插入排序的时候就只需要比较非常少的几次就可以插入到正确位置。
- 希尔排序就是先把整个序列排得相对比较有序,再进行插入排序的时候,需要比较的次数就会变得很少。
- 插入排序的增量(间隔)为 1,希尔排序相当于将这个间隔从最大为数组长度的一半一直降到 1,这一点在程序中体现的很清楚。当间隔很大时,比较的次数也会很少,在进行了几次大间隔的插入排序后,序列已经部分有序,这样再进行小间隔的插入排序也自然会比较很少的次数。
- 希尔排序就是将处在相同间隔的元素提取出来单独进行插入排序,然后逐步将间隔减小到 1 的过程。
- 在插入排序中,如果待排序列中的某个元素,距离有序数列中待插入位置非常远,就需要比较很多次才可以到达插入位置,这是因为待插入元素局部非常无序,比如说`[2, 3, 4, 5, 6, 7, 8, 1, ...]`,我们要插入 1,就必须将 1 和前面的 2-8 每个值都比较一下,就是因为 1 附近非常无序,想象一下,如果待插入元素附近比较有序,那么在进行插入排序的时候就只需要比较非常少的几次就可以插入到正确位置。
- 希尔排序就是先把整个序列排得相对比较有序,再进行插入排序的时候,需要比较的次数就会变得很少。
- 插入排序的增量(间隔)为 1,希尔排序相当于将这个间隔从最大为数组长度的一半一直降到 1,这一点在程序中体现的很清楚。当间隔很大时,比较的次数也会很少,在进行了几次大间隔的插入排序后,序列已经部分有序,这样再进行小间隔的插入排序也自然会比较很少的次数。
- 希尔排序就是将处在相同间隔的元素提取出来单独进行插入排序,然后逐步将间隔减小到 1 的过程。

## 代码示例

Expand Down
24 changes: 12 additions & 12 deletions basic/summary.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
- [基础算法通关](/basic/README.md)
- 排序算法
- [冒泡排序](/basic/sorting/BubbleSort/README.md)
- [插入排序](/basic/sorting/InsertionSort/README.md)
- [希尔排序](/basic/sorting/ShellSort/README.md)
- [选择排序](/basic/sorting/SelectionSort/README.md)
- [归并排序](/basic/sorting/MergeSort/README.md)
- [快速排序](/basic/sorting/QuickSort/README.md)
- [堆排序](/basic/sorting/HeapSort/README.md)
- [计数排序](/basic/sorting/CountingSort/README.md)
- 查找算法
- [二分查找](/basic/searching/BinarySearch/README.md)
- [基础算法通关](/basic/README.md)
- 排序算法
- [冒泡排序](/basic/sorting/BubbleSort/README.md)
- [插入排序](/basic/sorting/InsertionSort/README.md)
- [希尔排序](/basic/sorting/ShellSort/README.md)
- [选择排序](/basic/sorting/SelectionSort/README.md)
- [归并排序](/basic/sorting/MergeSort/README.md)
- [快速排序](/basic/sorting/QuickSort/README.md)
- [堆排序](/basic/sorting/HeapSort/README.md)
- [计数排序](/basic/sorting/CountingSort/README.md)
- 查找算法
- [二分查找](/basic/searching/BinarySearch/README.md)
6 changes: 3 additions & 3 deletions lcci/01.05.One Away/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ second = &quot;pal&quot;

接下来分情况讨论:

- 当 $m - n \gt 1$ 时,$\textit{first}$ 和 $\textit{second}$ 无法通过一次编辑得到,返回 `false`
- 当 $m = n$ 时,$\textit{first}$ 和 $\textit{second}$ 只有在且仅在有且仅有一个字符不同的情况下才能通过一次编辑得到;
- 当 $m - n = 1$ 时,$\textit{first}$ 和 $\textit{second}$ 只有在且仅在 $\textit{second}$ 是 $\textit{first}$ 删除一个字符后得到的情况下才能通过一次编辑得到,我们可以使用双指针来实现。
- 当 $m - n \gt 1$ 时,$\textit{first}$ 和 $\textit{second}$ 无法通过一次编辑得到,返回 `false`
- 当 $m = n$ 时,$\textit{first}$ 和 $\textit{second}$ 只有在且仅在有且仅有一个字符不同的情况下才能通过一次编辑得到;
- 当 $m - n = 1$ 时,$\textit{first}$ 和 $\textit{second}$ 只有在且仅在 $\textit{second}$ 是 $\textit{first}$ 删除一个字符后得到的情况下才能通过一次编辑得到,我们可以使用双指针来实现。

时间复杂度 $O(n)$,其中 $n$ 为字符串长度。空间复杂度 $O(1)$。

Expand Down
6 changes: 3 additions & 3 deletions lcci/01.05.One Away/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ Let the lengths of the strings $\textit{first}$ and $\textit{second}$ be $m$ and

Next, we discuss the following cases:

- When $m - n \gt 1$, $\textit{first}$ and $\textit{second}$ cannot be made equal with one edit, so return `false`;
- When $m = n$, $\textit{first}$ and $\textit{second}$ can be made equal with one edit only if there is exactly one different character;
- When $m - n = 1$, $\textit{first}$ and $\textit{second}$ can be made equal with one edit only if $\textit{second}$ is obtained by deleting one character from $\textit{first}$. We can use two pointers to achieve this.
- When $m - n \gt 1$, $\textit{first}$ and $\textit{second}$ cannot be made equal with one edit, so return `false`;
- When $m = n$, $\textit{first}$ and $\textit{second}$ can be made equal with one edit only if there is exactly one different character;
- When $m - n = 1$, $\textit{first}$ and $\textit{second}$ can be made equal with one edit only if $\textit{second}$ is obtained by deleting one character from $\textit{first}$. We can use two pointers to achieve this.

The time complexity is $O(n)$, where $n$ is the length of the string. The space complexity is $O(1)$.

Expand Down
2 changes: 1 addition & 1 deletion lcci/01.06.Compress String/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ The compressed string is &quot;a1b2c2d1&quot;, which is longer than the original

<p><strong>Note:</strong></p>

- `0 <= S.length <= 50000`
- `0 <= S.length <= 50000`

<!-- description:end -->

Expand Down
8 changes: 4 additions & 4 deletions lcci/02.07.Intersection of Two Linked Lists/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/02.07.Intersection%20

<p><b>Notes:</b></p>

- If the two linked lists have no intersection at all, return&nbsp;<code>null</code>.
- The linked lists must retain their original structure after the function returns.
- You may assume there are no cycles anywhere in the entire linked structure.
- Your code should preferably run in O(n) time and use only O(1) memory.
- If the two linked lists have no intersection at all, return&nbsp;<code>null</code>.
- The linked lists must retain their original structure after the function returns.
- You may assume there are no cycles anywhere in the entire linked structure.
- Your code should preferably run in O(n) time and use only O(1) memory.

<!-- description:end -->

Expand Down
8 changes: 4 additions & 4 deletions lcci/03.02.Min Stack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/03.02.Min%20Stack/REA

我们用两个栈来实现,其中`stk1` 用来存储数据,`stk2` 用来存储当前栈中的最小值。初始时,`stk2` 中存储一个极大值。

- 当我们向栈中压入一个元素 `x` 时,我们将 `x` 压入 `stk1`,并将 `min(x, stk2[-1])` 压入 `stk2`。
- 当我们从栈中弹出一个元素时,我们将 `stk1` 和 `stk2` 的栈顶元素都弹出。
- 当我们要获取当前栈中的栈顶元素时,我们只需要返回 `stk1` 的栈顶元素即可。
- 当我们要获取当前栈中的最小值时,我们只需要返回 `stk2` 的栈顶元素即可。
- 当我们向栈中压入一个元素 `x` 时,我们将 `x` 压入 `stk1`,并将 `min(x, stk2[-1])` 压入 `stk2`。
- 当我们从栈中弹出一个元素时,我们将 `stk1` 和 `stk2` 的栈顶元素都弹出。
- 当我们要获取当前栈中的栈顶元素时,我们只需要返回 `stk1` 的栈顶元素即可。
- 当我们要获取当前栈中的最小值时,我们只需要返回 `stk2` 的栈顶元素即可。

时间复杂度:对于每个操作,时间复杂度均为 $O(1)$,空间复杂度 $O(n)$。

Expand Down
8 changes: 4 additions & 4 deletions lcci/03.02.Min Stack/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ minStack.getMin(); --&gt; return -2.</pre>

We use two stacks to implement this, where `stk1` is used to store data, and `stk2` is used to store the current minimum value in the stack. Initially, `stk2` stores a very large value.

- When we push an element `x` into the stack, we push `x` into `stk1`, and push `min(x, stk2[-1])` into `stk2`.
- When we pop an element from the stack, we pop the top elements of both `stk1` and `stk2`.
- When we want to get the top element in the current stack, we just need to return the top element of `stk1`.
- When we want to get the minimum value in the current stack, we just need to return the top element of `stk2`.
- When we push an element `x` into the stack, we push `x` into `stk1`, and push `min(x, stk2[-1])` into `stk2`.
- When we pop an element from the stack, we pop the top elements of both `stk1` and `stk2`.
- When we want to get the top element in the current stack, we just need to return the top element of `stk1`.
- When we want to get the minimum value in the current stack, we just need to return the top element of `stk2`.

For each operation, the time complexity is $O(1)$, and the space complexity is $O(n)$.

Expand Down
6 changes: 3 additions & 3 deletions lcci/03.03.Stack of Plates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcci/03.03.Stack%20of%20Pl

我们可以使用一个栈列表 $stk$ 来模拟这个过程,初始时 $stk$ 为空。

- 当调用 $push$ 方法时,如果 $cap$ 为 0,直接返回。否则,如果 $stk$ 为空或者 $stk$ 的最后一个栈的长度大于等于 $cap$,则新建一个栈。然后将元素 $val$ 加入到 $stk$ 的最后一个栈中。时间复杂度为 $O(1)$。
- 当调用 $pop$ 方法时,返回 $popAt(|stk| - 1)$ 的结果。时间复杂度 $O(1)$。
- 当调用 $popAt$ 方法时,如果 $index$ 不在 $[0, |stk|)$ 范围内,返回 -1。否则,返回 $stk[index]$ 的栈顶元素,并将其弹出。如果弹出后 $stk[index]$ 为空,将其从 $stk$ 中删除。时间复杂度 $O(1)$。
- 当调用 $push$ 方法时,如果 $cap$ 为 0,直接返回。否则,如果 $stk$ 为空或者 $stk$ 的最后一个栈的长度大于等于 $cap$,则新建一个栈。然后将元素 $val$ 加入到 $stk$ 的最后一个栈中。时间复杂度为 $O(1)$。
- 当调用 $pop$ 方法时,返回 $popAt(|stk| - 1)$ 的结果。时间复杂度 $O(1)$。
- 当调用 $popAt$ 方法时,如果 $index$ 不在 $[0, |stk|)$ 范围内,返回 -1。否则,返回 $stk[index]$ 的栈顶元素,并将其弹出。如果弹出后 $stk[index]$ 为空,将其从 $stk$ 中删除。时间复杂度 $O(1)$。

空间复杂度为 $O(n)$,其中 $n$ 为元素个数。

Expand Down
Loading
Loading