Skip to content
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

feat: add solutions to lc problems: No.2978,2979 #2162

Merged
merged 3 commits into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
feat: add solution
  • Loading branch information
yanglbme committed Dec 28, 2023
commit ce5b8777b6b602632d45fd9d9c7dd4a0b50f6018
4 changes: 4 additions & 0 deletions solution/2900-2999/2978.Symmetric Coordinates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ The output table is sorted by X and Y in ascending order.

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

**方法一:窗口函数 + 自连接**

我们可以使用窗口函数 `ROW_NUMBER()` 来为每一行添加一个自增的序号,然后再自连接两张表,连接条件为 `p1.x = p2.y AND p1.y = p2.x AND p1.x <= p1.y AND p1.id != p2.id`,最后再排序去重即可。

<!-- tabs:start -->

### **SQL**
Expand Down
4 changes: 4 additions & 0 deletions solution/2900-2999/2978.Symmetric Coordinates/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ The output table is sorted by X and Y in ascending order.

## Solutions

**Solution 1: Window Function + Self Join**

We can use the window function `ROW_NUMBER()` to add an auto-incrementing sequence number to each row. Then, we perform a self join on the two tables, with the join conditions being `p1.x = p2.y AND p1.y = p2.x AND p1.x <= p1.y AND p1.id != p2.id`. Finally, we sort and remove duplicates.

<!-- tabs:start -->

### **SQL**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@

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

**方法一:Chicken McNugget 定理**

根据 Chicken McNugget 定理,两个互质的正整数 $a$ 和 $b$,最大不能表示的数为 $ab - a - b$。

时间复杂度 $O(1)$,空间复杂度 $O(1)$。

<!-- tabs:start -->

### **Python3**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@

## Solutions

**Solution 1: Chicken McNugget Theorem**

According to the Chicken McNugget Theorem, for two coprime positive integers $a$ and $b$, the largest number that cannot be expressed as a combination of $a$ and $b$ is $ab - a - b$.

The time complexity is $O(1)$, and the space complexity is $O(1)$.

<!-- tabs:start -->

### **Python3**
Expand Down