Skip to content

Commit

Permalink
feat: add contest data
Browse files Browse the repository at this point in the history
  • Loading branch information
yanglbme committed May 30, 2022
1 parent 460a8f2 commit ddd6a95
Show file tree
Hide file tree
Showing 187 changed files with 9,875 additions and 9,727 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.vscode
/node_modules
/solution/result.json
/solution/contest.json
/solution/raw.json
/lcof/lcof.json
/lcof/lcof_list.json
Expand Down
16 changes: 8 additions & 8 deletions basic/sorting/CountingSort/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
计数排序是一个非基于比较的排序算法,是一种空间换时间的算法,是通过元素的值来确定元素的位置, 适用于非负整数的排序(如果负数需要排序,那么需要使所有元素都添加上 `0-min` 之后再减去该值)

算法描述:
- 给定原数组中元素值的范围 `[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` 中剩下的元素

## 代码示例

Expand Down Expand Up @@ -68,6 +69,5 @@ func CountingSort(nums []int, min, max int) {

## 算法分析

- 时间复杂度 `O(n+k)`, 其中 `n` 为排序数组长度,`k` 为排序数组中数值的取值范围,当 `k < n` 时,时间复杂度为 `O(n)`
- 空间复杂度 `O(n+k)`, 其中 `n` 为排序数组长度,`k` 为排序数组中数值的取值范围,当 `k < n` 时,空间复杂度为 `O(n)`

- 时间复杂度 `O(n+k)`, 其中 `n` 为排序数组长度,`k` 为排序数组中数值的取值范围,当 `k < n` 时,时间复杂度为 `O(n)`
- 空间复杂度 `O(n+k)`, 其中 `n` 为排序数组长度,`k` 为排序数组中数值的取值范围,当 `k < n` 时,空间复杂度为 `O(n)`
1 change: 1 addition & 0 deletions basic/sorting/HeapSort/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ fn main() -> io::Result<()> {
```

### **Go**

```go
package main

Expand Down
16 changes: 8 additions & 8 deletions lcci/03.05.Sort of Stacks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,33 +160,33 @@ class SortedStack {

```ts
class SortedStack {
private stack: number[]
private stack: number[];

constructor() {
this.stack = []
this.stack = [];
}

push(val: number): void {
if (this.isEmpty() || this.peek() > val) {
this.stack.push(val)
return
this.stack.push(val);
return;
}

const tmp = this.stack.pop()
const tmp = this.stack.pop();
this.push(val);
this.stack.push(tmp);
}

pop(): void {
this.stack.pop()
this.stack.pop();
}

peek(): number {
return this.stack[this.stack.length - 1] ?? -1
return this.stack[this.stack.length - 1] ?? -1;
}

isEmpty(): boolean {
return this.stack.length === 0
return this.stack.length === 0;
}
}

Expand Down
16 changes: 8 additions & 8 deletions lcci/03.05.Sort of Stacks/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,33 +165,33 @@ class SortedStack {

```ts
class SortedStack {
private stack: number[]
private stack: number[];

constructor() {
this.stack = []
this.stack = [];
}

push(val: number): void {
if (this.isEmpty() || this.peek() > val) {
this.stack.push(val)
return
this.stack.push(val);
return;
}

const tmp = this.stack.pop()
const tmp = this.stack.pop();
this.push(val);
this.stack.push(tmp);
}

pop(): void {
this.stack.pop()
this.stack.pop();
}

peek(): number {
return this.stack[this.stack.length - 1] ?? -1
return this.stack[this.stack.length - 1] ?? -1;
}

isEmpty(): boolean {
return this.stack.length === 0
return this.stack.length === 0;
}
}

Expand Down
14 changes: 6 additions & 8 deletions lcci/04.06.Successor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@

<!-- 这里可写通用的实现逻辑 -->



<!-- tabs:start -->

### **Python3**
Expand Down Expand Up @@ -225,17 +223,17 @@ func inorderSuccessor(root *TreeNode, p *TreeNode) *TreeNode {
*/
var inorderSuccessor = function (root, p) {
if (root == null) {
return root
return root;
}
const { val, left, right } = root
const res = inorderSuccessor(left, p)
const { val, left, right } = root;
const res = inorderSuccessor(left, p);
if (res != null) {
return res
return res;
}
if (val > p.val) {
return root
return root;
}
return inorderSuccessor(right, p)
return inorderSuccessor(right, p);
};
```

Expand Down
12 changes: 6 additions & 6 deletions lcci/04.06.Successor/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,17 +236,17 @@ func inorderSuccessor(root *TreeNode, p *TreeNode) *TreeNode {
*/
var inorderSuccessor = function (root, p) {
if (root == null) {
return root
return root;
}
const { val, left, right } = root
const res = inorderSuccessor(left, p)
const { val, left, right } = root;
const res = inorderSuccessor(left, p);
if (res != null) {
return res
return res;
}
if (val > p.val) {
return root
return root;
}
return inorderSuccessor(right, p)
return inorderSuccessor(right, p);
};
```

Expand Down
4 changes: 2 additions & 2 deletions lcof/面试题13. 机器人的运动范围/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@

2. 根据公式判断 `(i, j)` 是否可进入:

- 可进入,并继续往右 `(i, j + 1)` 往下 `(i + 1, j)` 重新执行流程 2。
- 不可进入,退出结算。
- 可进入,并继续往右 `(i, j + 1)` 往下 `(i + 1, j)` 重新执行流程 2。
- 不可进入,退出结算。

3. 计算可进入区域的数量,返回即可。

Expand Down
4 changes: 2 additions & 2 deletions lcof/面试题57. 和为s的两个数字/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
- 存在,即 `return` 返回。
- 不存在,记录元素,继续遍历。

*复杂度*
_复杂度_

- 时间 **_O(N)_**
- 空间 **_O(N)_**
Expand All @@ -52,7 +52,7 @@

> 因为数组是有序的,指针变动对值的影响可预测。
*复杂度*
_复杂度_

- 时间 **_O(N)_**
- 空间 **_O(1)_**
Expand Down
2 changes: 1 addition & 1 deletion solution/0000-0099/0006.Zigzag Conversion/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ string convert(string s, int numRows);</pre>
<strong>输入:</strong>s = "PAYPALISHIRING", numRows = 3
<strong>输出:</strong>"PAHNAPLSIIGYIR"
</pre>

<strong>示例 2:</strong>

<pre>
Expand Down Expand Up @@ -59,7 +60,6 @@ P I
<li><code>1 <= numRows <= 1000</code></li>
</ul>


## 解法

<!-- 这里可写通用的实现逻辑 -->
Expand Down
1 change: 0 additions & 1 deletion solution/0000-0099/0006.Zigzag Conversion/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ P I
<li><code>1 &lt;= numRows &lt;= 1000</code></li>
</ul>


## Solutions

<!-- tabs:start -->
Expand Down
9 changes: 0 additions & 9 deletions solution/0000-0099/0028.Implement strStr()/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

<p>给你两个字符串&nbsp;<code>haystack</code> 和 <code>needle</code> ,请你在 <code>haystack</code> 字符串中找出 <code>needle</code> 字符串出现的第一个位置(下标从 0 开始)。如果不存在,则返回&nbsp; <code>-1</code><strong> </strong>。</p>

<p>&nbsp;</p>

<p><strong>说明:</strong></p>

<p>当&nbsp;<code>needle</code>&nbsp;是空字符串时,我们应当返回什么值呢?这是一个在面试中很好的问题。</p>
Expand All @@ -34,13 +32,6 @@
<strong>输出:</strong>-1
</pre>

<p><strong>示例 3:</strong></p>

<pre>
<strong>输入:</strong>haystack = "", needle = ""
<strong>输出:</strong>0
</pre>

<p>&nbsp;</p>

<p><strong>提示:</strong></p>
Expand Down
2 changes: 1 addition & 1 deletion solution/0000-0099/0038.Count and Say/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<li><code>countAndSay(n)</code> is the way you would &quot;say&quot; the digit string from <code>countAndSay(n-1)</code>, which is then converted into a different digit string.</li>
</ul>

<p>To determine how you &quot;say&quot; a digit string, split it into the <strong>minimal</strong> number of groups so that each group is a contiguous section all of the <strong>same character.</strong> Then for each group, say the number of characters, then say the character. To convert the saying into a digit string, replace the counts with a number and concatenate every saying.</p>
<p>To determine how you &quot;say&quot; a digit string, split it into the <strong>minimal</strong> number of substrings such that each substring contains exactly <strong>one</strong> unique digit. Then for each substring, say the number of digits, then say the digit. Finally, concatenate every said digit.</p>

<p>For example, the saying and conversion for digit string <code>&quot;3322251&quot;</code>:</p>
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0000-0099/0038.Count%20and%20Say/images/countandsay.jpg" style="width: 581px; height: 172px;" />
Expand Down
2 changes: 2 additions & 0 deletions solution/0000-0099/0051.N-Queens/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

<!-- 这里写题目描述 -->

<p>按照国际象棋的规则,皇后可以攻击与之处在同一行或同一列或同一斜线上的棋子。</p>

<p><strong>n&nbsp;皇后问题</strong> 研究的是如何将 <code>n</code>&nbsp;个皇后放置在 <code>n×n</code> 的棋盘上,并且使皇后彼此之间不能相互攻击。</p>

<p>给你一个整数 <code>n</code> ,返回所有不同的&nbsp;<strong>n<em>&nbsp;</em>皇后问题</strong> 的解决方案。</p>
Expand Down
2 changes: 1 addition & 1 deletion solution/0000-0099/0057.Insert Interval/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class Solution:
ed = max(ed, e)
ans.append([st, ed])
return ans

intervals.append(newInterval)
return merge(intervals)
```
Expand Down
2 changes: 1 addition & 1 deletion solution/0000-0099/0057.Insert Interval/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Solution:
ed = max(ed, e)
ans.append([st, ed])
return ans

intervals.append(newInterval)
return merge(intervals)
```
Expand Down
2 changes: 1 addition & 1 deletion solution/0000-0099/0058.Length of Last Word/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## Description

<p>Given a string <code>s</code> consisting&nbsp;of some words separated by some number of spaces, return <em>the length of the <strong>last</strong> word in the string.</em></p>
<p>Given a string <code>s</code> consisting of words and spaces, return <em>the length of the <strong>last</strong> word in the string.</em></p>

<p>A <strong>word</strong> is a maximal substring consisting of non-space characters only.</p>

Expand Down
1 change: 0 additions & 1 deletion solution/0100-0199/0146.LRU Cache/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ lRUCache.get(4); // 返回 4
<li>最多调用 <code>2 * 10<sup>5</sup></code> 次 <code>get</code> 和 <code>put</code></li>
</ul>


## 解法

<!-- 这里可写通用的实现逻辑 -->
Expand Down
1 change: 0 additions & 1 deletion solution/0100-0199/0146.LRU Cache/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ lRUCache.get(4); // return 4
<li>At most 2<code>&nbsp;* 10<sup>5</sup></code>&nbsp;calls will be made to <code>get</code> and <code>put</code>.</li>
</ul>


## Solutions

<!-- tabs:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ sol.read (buf, 1); // 我们已经到达文件的末尾,不能读取更多的
<li><code>1 &lt;= queries[i] &lt;= 500</code></li>
</ul>


## 解法

<!-- 这里可写通用的实现逻辑 -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ sol.read(buf, 1); // We have reached the end of file, no more characters can be
<li><code>1 &lt;= queries[i] &lt;= 500</code></li>
</ul>


## Solutions

<!-- tabs:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## Description

<p>Given a string <code>columnTitle</code> that represents the column title as appear in an Excel sheet, return <em>its corresponding column number</em>.</p>
<p>Given a string <code>columnTitle</code> that represents the column title as appears in an Excel sheet, return <em>its corresponding column number</em>.</p>

<p>For example:</p>

Expand Down
12 changes: 6 additions & 6 deletions solution/0100-0199/0175.Combine Two Tables/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
| FirstName | varchar |
| LastName | varchar |
+-------------+---------+
personId是该表的主键列
该表包含一些人的ID和他们的姓和名的信息
personId 是该表的主键列
该表包含一些人的 ID 和他们的姓和名的信息
</pre>

<p>&nbsp;</p>
Expand All @@ -33,13 +33,13 @@ personId是该表的主键列。
| City | varchar |
| State | varchar |
+-------------+---------+
addressId是该表的主键列
该表的每一行都包含一个ID = PersonId的人的城市和州的信息
addressId 是该表的主键列
该表的每一行都包含一个 ID = PersonId 的人的城市和州的信息
</pre>

<p>&nbsp;</p>

<p>编写一个SQL查询来报告 <code>Person</code> 表中每个人的姓、名、城市和状态。如果 <code>personId</code> 的地址不在&nbsp;<code>Address</code>&nbsp;表中,则报告为空 &nbsp;<code>null</code>&nbsp;。</p>
<p>编写一个SQL查询来报告 <code>Person</code> 表中每个人的姓、名、城市和州。如果 <code>personId</code> 的地址不在&nbsp;<code>Address</code>&nbsp;表中,则报告为空 &nbsp;<code>null</code>&nbsp;。</p>

<p>以 <strong>任意顺序</strong> 返回结果表。</p>

Expand Down Expand Up @@ -73,7 +73,7 @@ Address表:
| Bob | Alice | New York City | New York |
+-----------+----------+---------------+----------+
<strong>解释:</strong>
地址表中没有 personId = 1 的地址,所以它们的城市和州返回null
地址表中没有 personId = 1 的地址,所以它们的城市和州返回 null
addressId = 1 包含了 personId = 2 的地址信息。</pre>

## 解法
Expand Down
1 change: 0 additions & 1 deletion solution/0100-0199/0191.Number of 1 Bits/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ var hammingWeight = function (n) {
};
```


### **Rust**

```rust
Expand Down
Loading

0 comments on commit ddd6a95

Please sign in to comment.