Skip to content

[pull] main from doocs:main #218

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
merged 6 commits into from
Apr 6, 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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lcp/LCP 01. 猜数字/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func game(guess []int, answer []int) int {
var game = function (guess, answer) {
let ans = 0;
for (let i = 0; i < 3; ++i) {
ans += guess[i] == answer[i];
ans += guess[i] === answer[i];
}
return ans;
};
Expand Down
2 changes: 1 addition & 1 deletion lcp/LCP 01. 猜数字/Solution.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
var game = function (guess, answer) {
let ans = 0;
for (let i = 0; i < 3; ++i) {
ans += guess[i] == answer[i];
ans += guess[i] === answer[i];
}
return ans;
};
2 changes: 1 addition & 1 deletion lcp/LCP 02. 分式化简/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func fraction(cont []int) []int {
*/
var fraction = function (cont) {
function dfs(i) {
if (i == cont.length - 1) {
if (i === cont.length - 1) {
return [cont[i], 1];
}
const [a, b] = dfs(i + 1);
Expand Down
2 changes: 1 addition & 1 deletion lcp/LCP 02. 分式化简/Solution.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
var fraction = function (cont) {
function dfs(i) {
if (i == cont.length - 1) {
if (i === cont.length - 1) {
return [cont[i], 1];
}
const [a, b] = dfs(i + 1);
Expand Down
12 changes: 12 additions & 0 deletions lcp/LCP 06. 拿硬币/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ int minCount(int* coins, int coinsSize) {
}
```

### **TypeScript**

```ts
function minCount(coins: number[]): number {
let ans = 0;
for (const coin of coins) {
ans += Math.floor((coin + 1) / 2);
}
return ans;
}
```

### **...**

```
Expand Down
7 changes: 7 additions & 0 deletions lcp/LCP 06. 拿硬币/Solution.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function minCount(coins: number[]): number {
let ans = 0;
for (const coin of coins) {
ans += Math.floor((coin + 1) / 2);
}
return ans;
}
2 changes: 2 additions & 0 deletions lcp/LCP 57. 打地鼠/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
<!-- 这里写题目描述 -->

欢迎各位勇者来到力扣城,本次试炼主题为「打地鼠」。

![middle_img_v2_d5d09656-0616-4a80-845e-ece461c5ba9g.png](https://fastly.jsdelivr.net/gh/doocs/leetcode@main/lcp/LCP%2057.%20%E6%89%93%E5%9C%B0%E9%BC%A0/images/1650273183-nZIijm-middle_img_v2_d5d09656-0616-4a80-845e-ece461c5ba9g.png)

勇者面前有一个大小为 `3*3` 的打地鼠游戏机,地鼠将随机出现在各个位置,`moles[i] = [t,x,y]` 表示在第 `t` 秒会有地鼠出现在 `(x,y)` 位置上,并于第 `t+1` 秒该地鼠消失。

勇者有一把可敲打地鼠的锤子,初始时刻(即第 `0` 秒)锤子位于正中间的格子 `(1,1)`,锤子的使用规则如下:
Expand Down
4 changes: 2 additions & 2 deletions lcp/LCP 60. 力扣泡泡龙/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
> 输出:`11`
>
> 解释:勇者的最佳方案如图所示
> ![image.png](https://fastly.jsdelivr.net/gh/doocs/leetcode@main/lcp/LCP%2060.%20%E5%8A%9B%E6%89%A3%E6%B3%A1%E6%B3%A1%E9%BE%99/images/1648180809-XSWPLu-image.png)
> <br>![image.png](https://fastly.jsdelivr.net/gh/doocs/leetcode@main/lcp/LCP%2060.%20%E5%8A%9B%E6%89%A3%E6%B3%A1%E6%B3%A1%E9%BE%99/images/1648180809-XSWPLu-image.png)

**示例 2:**

Expand All @@ -34,7 +34,7 @@
> 输出:`9`
>
> 解释:勇者击破 6 节点,此时「层和」最大为 3+5+1 = 9
> ![image.png](https://fastly.jsdelivr.net/gh/doocs/leetcode@main/lcp/LCP%2060.%20%E5%8A%9B%E6%89%A3%E6%B3%A1%E6%B3%A1%E9%BE%99/images/1648180769-TLpYop-image.png)
> <br>![image.png](https://fastly.jsdelivr.net/gh/doocs/leetcode@main/lcp/LCP%2060.%20%E5%8A%9B%E6%89%A3%E6%B3%A1%E6%B3%A1%E9%BE%99/images/1648180769-TLpYop-image.png)

**示例 3:**

Expand Down
34 changes: 28 additions & 6 deletions lcp/LCP 62. 交通枢纽/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
> 解释:如下图所示:
> 地点 `0,1,2` 各有一条通往地点 `3` 的交通专线,
> 且地点 `3` 不存在任何**通往其他地点**的交通专线。
> ![image.png](https://fastly.jsdelivr.net/gh/doocs/leetcode@main/lcp/LCP%2062.%20%E4%BA%A4%E9%80%9A%E6%9E%A2%E7%BA%BD/images/1663902572-yOlUCr-image.png)
><br><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/lcp/LCP%2062.%20%E4%BA%A4%E9%80%9A%E6%9E%A2%E7%BA%BD/images/1663902572-yOlUCr-image.png" style="width: 200px;" />

**示例 2:**

Expand All @@ -34,7 +34,7 @@
> 输出:`-1`
>
> 解释:如下图所示:不存在满足 **交通枢纽** 的地点。
> ![image.png](https://fastly.jsdelivr.net/gh/doocs/leetcode@main/lcp/LCP%2062.%20%E4%BA%A4%E9%80%9A%E6%9E%A2%E7%BA%BD/images/1663902595-McsEkY-image.png)
><br><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/lcp/LCP%2062.%20%E4%BA%A4%E9%80%9A%E6%9E%A2%E7%BA%BD/images/1663902595-McsEkY-image.png" style="width: 200px;" />

**提示:**

Expand Down Expand Up @@ -68,7 +68,11 @@ class Solution:
ind = Counter()
outd = Counter()
s = set()
vis = set()
for a, b in path:
if (a, b) in vis:
continue
vis.add((a, b))
s.add(a)
s.add(b)
outd[a] += 1
Expand All @@ -89,12 +93,15 @@ class Solution {
int[] ind = new int[1001];
int[] outd = new int[1001];
Set<Integer> s = new HashSet<>();
Set<Integer> vis = new HashSet<>();
for (int[] p : path) {
int a = p[0], b = p[1];
s.add(a);
s.add(b);
ind[b]++;
outd[a]++;
if (vis.add(a * 1000 + b)) {
s.add(a);
s.add(b);
ind[b]++;
outd[a]++;
}
}
for (int c : s) {
if (ind[c] == s.size() - 1 && outd[c] == 0) {
Expand All @@ -115,8 +122,13 @@ public:
int ind[1001]{};
int outd[1001]{};
unordered_set<int> s;
unordered_set<int> vis;
for (auto& p : path) {
int a = p[0], b = p[1];
if (vis.count(a * 1000 + b)) {
continue;
}
vis.insert(a * 1000 + b);
s.insert(a);
s.insert(b);
ind[b]++;
Expand All @@ -139,8 +151,13 @@ func transportationHub(path [][]int) int {
ind := [1001]int{}
outd := [1001]int{}
s := map[int]struct{}{}
vis := map[int]bool{}
for _, p := range path {
a, b := p[0], p[1]
if vis[a*1000+b] {
continue
}
vis[a*1000+b] = true
s[a] = struct{}{}
s[b] = struct{}{}
outd[a]++
Expand All @@ -162,7 +179,12 @@ function transportationHub(path: number[][]): number {
const ind: number[] = new Array(1001).fill(0);
const outd: number[] = new Array(1001).fill(0);
const s: Set<number> = new Set();
const vis: Set<number> = new Set();
for (const [a, b] of path) {
if (vis.has(a * 1000 + b)) {
continue;
}
vis.add(a * 1000 + b);
s.add(a);
s.add(b);
ind[b]++;
Expand Down
5 changes: 5 additions & 0 deletions lcp/LCP 62. 交通枢纽/Solution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ class Solution {
int ind[1001]{};
int outd[1001]{};
unordered_set<int> s;
unordered_set<int> vis;
for (auto& p : path) {
int a = p[0], b = p[1];
if (vis.count(a * 1000 + b)) {
continue;
}
vis.insert(a * 1000 + b);
s.insert(a);
s.insert(b);
ind[b]++;
Expand Down
5 changes: 5 additions & 0 deletions lcp/LCP 62. 交通枢纽/Solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ func transportationHub(path [][]int) int {
ind := [1001]int{}
outd := [1001]int{}
s := map[int]struct{}{}
vis := map[int]bool{}
for _, p := range path {
a, b := p[0], p[1]
if vis[a*1000+b] {
continue
}
vis[a*1000+b] = true
s[a] = struct{}{}
s[b] = struct{}{}
outd[a]++
Expand Down
11 changes: 7 additions & 4 deletions lcp/LCP 62. 交通枢纽/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ public int transportationHub(int[][] path) {
int[] ind = new int[1001];
int[] outd = new int[1001];
Set<Integer> s = new HashSet<>();
Set<Integer> vis = new HashSet<>();
for (int[] p : path) {
int a = p[0], b = p[1];
s.add(a);
s.add(b);
ind[b]++;
outd[a]++;
if (vis.add(a * 1000 + b)) {
s.add(a);
s.add(b);
ind[b]++;
outd[a]++;
}
}
for (int c : s) {
if (ind[c] == s.size() - 1 && outd[c] == 0) {
Expand Down
4 changes: 4 additions & 0 deletions lcp/LCP 62. 交通枢纽/Solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ def transportationHub(self, path: List[List[int]]) -> int:
ind = Counter()
outd = Counter()
s = set()
vis = set()
for a, b in path:
if (a, b) in vis:
continue
vis.add((a, b))
s.add(a)
s.add(b)
outd[a] += 1
Expand Down
5 changes: 5 additions & 0 deletions lcp/LCP 62. 交通枢纽/Solution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ function transportationHub(path: number[][]): number {
const ind: number[] = new Array(1001).fill(0);
const outd: number[] = new Array(1001).fill(0);
const s: Set<number> = new Set();
const vis: Set<number> = new Set();
for (const [a, b] of path) {
if (vis.has(a * 1000 + b)) {
continue;
}
vis.add(a * 1000 + b);
s.add(a);
s.add(b);
ind[b]++;
Expand Down
Loading