From a9bada91b7481a424b75c04e63ca8230cbc9b7ec Mon Sep 17 00:00:00 2001 From: thinkasany <117748716+thinkasany@users.noreply.github.com> Date: Thu, 6 Apr 2023 09:01:45 +0800 Subject: [PATCH 1/6] style: resize document image size (#967) --- .../README.md" | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git "a/lcp/LCP 62. \344\272\244\351\200\232\346\236\242\347\272\275/README.md" "b/lcp/LCP 62. \344\272\244\351\200\232\346\236\242\347\272\275/README.md" index b2b450dfb7cc3..529ffca61b679 100644 --- "a/lcp/LCP 62. \344\272\244\351\200\232\346\236\242\347\272\275/README.md" +++ "b/lcp/LCP 62. \344\272\244\351\200\232\346\236\242\347\272\275/README.md" @@ -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) +>
**示例 2:** @@ -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) +>
**提示:** From 7895a5f21939f7213cac60f1e70d30ba0eaeafd1 Mon Sep 17 00:00:00 2001 From: yanglbme Date: Thu, 6 Apr 2023 09:15:11 +0800 Subject: [PATCH 2/6] feat: update solutions to lcp problem: No.62 --- .../README.md" | 30 ++++++++++++++++--- .../Solution.cpp" | 5 ++++ .../Solution.go" | 5 ++++ .../Solution.java" | 11 ++++--- .../Solution.py" | 4 +++ .../Solution.ts" | 5 ++++ 6 files changed, 52 insertions(+), 8 deletions(-) diff --git "a/lcp/LCP 62. \344\272\244\351\200\232\346\236\242\347\272\275/README.md" "b/lcp/LCP 62. \344\272\244\351\200\232\346\236\242\347\272\275/README.md" index 529ffca61b679..dab6895b2c4d0 100644 --- "a/lcp/LCP 62. \344\272\244\351\200\232\346\236\242\347\272\275/README.md" +++ "b/lcp/LCP 62. \344\272\244\351\200\232\346\236\242\347\272\275/README.md" @@ -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 @@ -89,12 +93,15 @@ class Solution { int[] ind = new int[1001]; int[] outd = new int[1001]; Set s = new HashSet<>(); + Set 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) { @@ -115,8 +122,13 @@ public: int ind[1001]{}; int outd[1001]{}; unordered_set s; + unordered_set 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]++; @@ -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]++ @@ -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 = new Set(); + const vis: Set = 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]++; diff --git "a/lcp/LCP 62. \344\272\244\351\200\232\346\236\242\347\272\275/Solution.cpp" "b/lcp/LCP 62. \344\272\244\351\200\232\346\236\242\347\272\275/Solution.cpp" index 1bc5792b9fa53..0e1bb018e636c 100644 --- "a/lcp/LCP 62. \344\272\244\351\200\232\346\236\242\347\272\275/Solution.cpp" +++ "b/lcp/LCP 62. \344\272\244\351\200\232\346\236\242\347\272\275/Solution.cpp" @@ -4,8 +4,13 @@ class Solution { int ind[1001]{}; int outd[1001]{}; unordered_set s; + unordered_set 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]++; diff --git "a/lcp/LCP 62. \344\272\244\351\200\232\346\236\242\347\272\275/Solution.go" "b/lcp/LCP 62. \344\272\244\351\200\232\346\236\242\347\272\275/Solution.go" index 753747597ec12..b482c0430f586 100644 --- "a/lcp/LCP 62. \344\272\244\351\200\232\346\236\242\347\272\275/Solution.go" +++ "b/lcp/LCP 62. \344\272\244\351\200\232\346\236\242\347\272\275/Solution.go" @@ -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]++ diff --git "a/lcp/LCP 62. \344\272\244\351\200\232\346\236\242\347\272\275/Solution.java" "b/lcp/LCP 62. \344\272\244\351\200\232\346\236\242\347\272\275/Solution.java" index 9406afd6bfc8b..3e4cb0301907c 100644 --- "a/lcp/LCP 62. \344\272\244\351\200\232\346\236\242\347\272\275/Solution.java" +++ "b/lcp/LCP 62. \344\272\244\351\200\232\346\236\242\347\272\275/Solution.java" @@ -3,12 +3,15 @@ public int transportationHub(int[][] path) { int[] ind = new int[1001]; int[] outd = new int[1001]; Set s = new HashSet<>(); + Set 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) { diff --git "a/lcp/LCP 62. \344\272\244\351\200\232\346\236\242\347\272\275/Solution.py" "b/lcp/LCP 62. \344\272\244\351\200\232\346\236\242\347\272\275/Solution.py" index f1ee49a7b45f7..fc3dc11cb780b 100644 --- "a/lcp/LCP 62. \344\272\244\351\200\232\346\236\242\347\272\275/Solution.py" +++ "b/lcp/LCP 62. \344\272\244\351\200\232\346\236\242\347\272\275/Solution.py" @@ -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 diff --git "a/lcp/LCP 62. \344\272\244\351\200\232\346\236\242\347\272\275/Solution.ts" "b/lcp/LCP 62. \344\272\244\351\200\232\346\236\242\347\272\275/Solution.ts" index e6b8d8ab050b2..a48f728a49fe0 100644 --- "a/lcp/LCP 62. \344\272\244\351\200\232\346\236\242\347\272\275/Solution.ts" +++ "b/lcp/LCP 62. \344\272\244\351\200\232\346\236\242\347\272\275/Solution.ts" @@ -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 = new Set(); + const vis: Set = 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]++; From 1ea57a85d4a6c6d682a2b25363751acda80c1e01 Mon Sep 17 00:00:00 2001 From: yanglbme Date: Thu, 6 Apr 2023 10:10:21 +0800 Subject: [PATCH 3/6] feat: add solutions to lcp problem: No.63 --- .../README.md" | 186 ++++++++++++++++++ .../Solution.cpp" | 45 +++++ .../Solution.go" | 41 ++++ .../Solution.java" | 53 +++++ .../Solution.py" | 31 +++ 5 files changed, 356 insertions(+) create mode 100644 "lcp/LCP 63. \345\274\271\347\217\240\346\270\270\346\210\217/Solution.cpp" create mode 100644 "lcp/LCP 63. \345\274\271\347\217\240\346\270\270\346\210\217/Solution.go" create mode 100644 "lcp/LCP 63. \345\274\271\347\217\240\346\270\270\346\210\217/Solution.java" create mode 100644 "lcp/LCP 63. \345\274\271\347\217\240\346\270\270\346\210\217/Solution.py" diff --git "a/lcp/LCP 63. \345\274\271\347\217\240\346\270\270\346\210\217/README.md" "b/lcp/LCP 63. \345\274\271\347\217\240\346\270\270\346\210\217/README.md" index e46b4236055e3..a0ffc7744564a 100644 --- "a/lcp/LCP 63. \345\274\271\347\217\240\346\270\270\346\210\217/README.md" +++ "b/lcp/LCP 63. \345\274\271\347\217\240\346\270\270\346\210\217/README.md" @@ -64,6 +64,14 @@ +**方法一:模拟** + +我们注意到,从不同的位置打入弹珠,弹珠的前进路线不会重叠。因此,我们可以枚举所有可能的打入位置,然后模拟弹珠的前进过程,判断是否能够入洞,是则将该位置加入答案。 + +在实现上,我们定义一个方向数组 $dirs=[0,1,0,-1,0]$,对于 $d \in [0,..3]$,其中 $(dirs[d], dirs[d + 1])$ 表示弹珠的前进方向,分别对应 “右、下、左、上”四个方向。如果弹珠遇到 “W” 转向器,则 $d=(d+3) \bmod 4$,如果遇到 “E” 转向器,则 $d=(d+1) \bmod 4$。 + +时间复杂度 $O(m \times n)$,空间复杂度 $O(1)$。其中 $m$ 和 $n$ 分别为弹珠盘的行数和列数。 + ### **Python3** @@ -71,7 +79,37 @@ ```python +class Solution: + def ballGame(self, num: int, plate: List[str]) -> List[List[int]]: + def check(i, j, d): + k = num + while plate[i][j] != 'O': + if k == 0: + return False + if plate[i][j] == 'W': + d = (d + 3) % 4 + elif plate[i][j] == 'E': + d = (d + 1) % 4 + i, j = i + dirs[d], j + dirs[d + 1] + if not (0 <= i < m and 0 <= j < n): + return False + k -= 1 + return True + dirs = (0, 1, 0, -1, 0) + m, n = len(plate), len(plate[0]) + ans = [] + for i in range(1, m - 1): + if plate[i][0] == '.' and check(i, 0, 0): + ans.append([i, 0]) + if plate[i][n - 1] == '.' and check(i, n - 1, 2): + ans.append([i, n - 1]) + for j in range(1, n - 1): + if plate[0][j] == '.' and check(0, j, 1): + ans.append([0, j]) + if plate[m - 1][j] == '.' and check(m - 1, j, 3): + ans.append([m - 1, j]) + return ans ``` ### **Java** @@ -79,7 +117,155 @@ ```java +class Solution { + private String[] plate; + private int num; + private int m; + private int n; + private final int[] dirs = {0, 1, 0, -1, 0}; + + public int[][] ballGame(int num, String[] plate) { + this.num = num; + this.plate = plate; + this.m = plate.length; + this.n = plate[0].length(); + List ans = new ArrayList<>(); + for (int i = 1; i < m - 1; ++i) { + if (plate[i].charAt(0) == '.' && check(i, 0, 0)) { + ans.add(new int[]{i, 0}); + } + if (plate[i].charAt(n - 1) == '.' && check(i, n - 1, 2)) { + ans.add(new int[]{i, n - 1}); + } + } + for (int j = 1; j < n - 1; ++j) { + if (plate[0].charAt(j) == '.' && check(0, j, 1)) { + ans.add(new int[]{0, j}); + } + if (plate[m - 1].charAt(j) == '.' && check(m - 1, j, 3)) { + ans.add(new int[]{m - 1, j}); + } + } + return ans.toArray(new int[0][]); + } + + private boolean check(int i, int j, int d) { + int k = num; + while (plate[i].charAt(j) != 'O') { + if (k == 0) { + return false; + } + if (plate[i].charAt(j) == 'W') { + d = (d + 3) % 4; + } else if (plate[i].charAt(j) == 'E') { + d = (d + 1) % 4; + } + i = i + dirs[d]; + j = j + dirs[d + 1]; + if (i < 0 || i >= m || j < 0 || j >= n) { + return false; + } + --k; + } + return true; + } +} +``` + +### **C++** + +```cpp +class Solution { +public: + vector> ballGame(int num, vector& plate) { + int m = plate.size(), n = plate[0].size(); + vector> ans; + int dirs[5] = {0, 1, 0, -1, 0}; + auto check = [&](int i, int j, int d) -> bool { + int k = num; + while (plate[i][j] != 'O') { + if (k == 0) { + return false; + } + if (plate[i][j] == 'W') { + d = (d + 3) % 4; + } else if (plate[i][j] == 'E') { + d = (d + 1) % 4; + } + i += dirs[d]; + j += dirs[d + 1]; + if (i < 0 || i >= m || j < 0 || j >= n) { + return false; + } + --k; + } + return true; + }; + for (int i = 1; i < m - 1; ++i) { + if (plate[i][0] == '.' && check(i, 0, 0)) { + ans.push_back({i, 0}); + } + if (plate[i][n - 1] == '.' && check(i, n - 1, 2)) { + ans.push_back({i, n - 1}); + } + } + for (int j = 1; j < n - 1; ++j) { + if (plate[0][j] == '.' && check(0, j, 1)) { + ans.push_back({0, j}); + } + if (plate[m - 1][j] == '.' && check(m - 1, j, 3)) { + ans.push_back({m - 1, j}); + } + } + return ans; + } +}; +``` + +### **Go** +```go +func ballGame(num int, plate []string) (ans [][]int) { + dirs := [5]int{0, 1, 0, -1, 0} + m, n := len(plate), len(plate[0]) + check := func(i, j, d int) bool { + k := num + for plate[i][j] != 'O' { + if k == 0 { + return false + } + if plate[i][j] == 'W' { + d = (d + 3) % 4 + } else if plate[i][j] == 'E' { + d = (d + 1) % 4 + } + i += dirs[d] + j += dirs[d+1] + if i < 0 || i >= m || j < 0 || j >= n { + return false + } + k-- + } + return true + } + for i := 1; i < m-1; i++ { + if plate[i][0] == '.' && check(i, 0, 0) { + ans = append(ans, []int{i, 0}) + } + if plate[i][n-1] == '.' && check(i, n-1, 2) { + ans = append(ans, []int{i, n - 1}) + } + } + for j := 1; j < n-1; j++ { + if plate[0][j] == '.' && check(0, j, 1) { + ans = append(ans, []int{0, j}) + } + if plate[m-1][j] == '.' && check(m-1, j, 3) { + ans = append(ans, []int{m - 1, j}) + } + } + return +} ``` ### **...** diff --git "a/lcp/LCP 63. \345\274\271\347\217\240\346\270\270\346\210\217/Solution.cpp" "b/lcp/LCP 63. \345\274\271\347\217\240\346\270\270\346\210\217/Solution.cpp" new file mode 100644 index 0000000000000..2836138873a6a --- /dev/null +++ "b/lcp/LCP 63. \345\274\271\347\217\240\346\270\270\346\210\217/Solution.cpp" @@ -0,0 +1,45 @@ +class Solution { +public: + vector> ballGame(int num, vector& plate) { + int m = plate.size(), n = plate[0].size(); + vector> ans; + int dirs[5] = {0, 1, 0, -1, 0}; + auto check = [&](int i, int j, int d) -> bool { + int k = num; + while (plate[i][j] != 'O') { + if (k == 0) { + return false; + } + if (plate[i][j] == 'W') { + d = (d + 3) % 4; + } else if (plate[i][j] == 'E') { + d = (d + 1) % 4; + } + i += dirs[d]; + j += dirs[d + 1]; + if (i < 0 || i >= m || j < 0 || j >= n) { + return false; + } + --k; + } + return true; + }; + for (int i = 1; i < m - 1; ++i) { + if (plate[i][0] == '.' && check(i, 0, 0)) { + ans.push_back({i, 0}); + } + if (plate[i][n - 1] == '.' && check(i, n - 1, 2)) { + ans.push_back({i, n - 1}); + } + } + for (int j = 1; j < n - 1; ++j) { + if (plate[0][j] == '.' && check(0, j, 1)) { + ans.push_back({0, j}); + } + if (plate[m - 1][j] == '.' && check(m - 1, j, 3)) { + ans.push_back({m - 1, j}); + } + } + return ans; + } +}; \ No newline at end of file diff --git "a/lcp/LCP 63. \345\274\271\347\217\240\346\270\270\346\210\217/Solution.go" "b/lcp/LCP 63. \345\274\271\347\217\240\346\270\270\346\210\217/Solution.go" new file mode 100644 index 0000000000000..eae8f30aa2f60 --- /dev/null +++ "b/lcp/LCP 63. \345\274\271\347\217\240\346\270\270\346\210\217/Solution.go" @@ -0,0 +1,41 @@ +func ballGame(num int, plate []string) (ans [][]int) { + dirs := [5]int{0, 1, 0, -1, 0} + m, n := len(plate), len(plate[0]) + check := func(i, j, d int) bool { + k := num + for plate[i][j] != 'O' { + if k == 0 { + return false + } + if plate[i][j] == 'W' { + d = (d + 3) % 4 + } else if plate[i][j] == 'E' { + d = (d + 1) % 4 + } + i += dirs[d] + j += dirs[d+1] + if i < 0 || i >= m || j < 0 || j >= n { + return false + } + k-- + } + return true + } + for i := 1; i < m-1; i++ { + if plate[i][0] == '.' && check(i, 0, 0) { + ans = append(ans, []int{i, 0}) + } + if plate[i][n-1] == '.' && check(i, n-1, 2) { + ans = append(ans, []int{i, n - 1}) + } + } + for j := 1; j < n-1; j++ { + if plate[0][j] == '.' && check(0, j, 1) { + ans = append(ans, []int{0, j}) + } + if plate[m-1][j] == '.' && check(m-1, j, 3) { + ans = append(ans, []int{m - 1, j}) + } + } + return +} \ No newline at end of file diff --git "a/lcp/LCP 63. \345\274\271\347\217\240\346\270\270\346\210\217/Solution.java" "b/lcp/LCP 63. \345\274\271\347\217\240\346\270\270\346\210\217/Solution.java" new file mode 100644 index 0000000000000..2d6a5daa61510 --- /dev/null +++ "b/lcp/LCP 63. \345\274\271\347\217\240\346\270\270\346\210\217/Solution.java" @@ -0,0 +1,53 @@ +class Solution { + private String[] plate; + private int num; + private int m; + private int n; + private final int[] dirs = {0, 1, 0, -1, 0}; + + public int[][] ballGame(int num, String[] plate) { + this.num = num; + this.plate = plate; + this.m = plate.length; + this.n = plate[0].length(); + List ans = new ArrayList<>(); + for (int i = 1; i < m - 1; ++i) { + if (plate[i].charAt(0) == '.' && check(i, 0, 0)) { + ans.add(new int[]{i, 0}); + } + if (plate[i].charAt(n - 1) == '.' && check(i, n - 1, 2)) { + ans.add(new int[]{i, n - 1}); + } + } + for (int j = 1; j < n - 1; ++j) { + if (plate[0].charAt(j) == '.' && check(0, j, 1)) { + ans.add(new int[]{0, j}); + } + if (plate[m - 1].charAt(j) == '.' && check(m - 1, j, 3)) { + ans.add(new int[]{m - 1, j}); + } + } + return ans.toArray(new int[0][]); + } + + private boolean check(int i, int j, int d) { + int k = num; + while (plate[i].charAt(j) != 'O') { + if (k == 0) { + return false; + } + if (plate[i].charAt(j) == 'W') { + d = (d + 3) % 4; + } else if (plate[i].charAt(j) == 'E') { + d = (d + 1) % 4; + } + i = i + dirs[d]; + j = j + dirs[d + 1]; + if (i < 0 || i >= m || j < 0 || j >= n) { + return false; + } + --k; + } + return true; + } +} \ No newline at end of file diff --git "a/lcp/LCP 63. \345\274\271\347\217\240\346\270\270\346\210\217/Solution.py" "b/lcp/LCP 63. \345\274\271\347\217\240\346\270\270\346\210\217/Solution.py" new file mode 100644 index 0000000000000..9c9926ab0681d --- /dev/null +++ "b/lcp/LCP 63. \345\274\271\347\217\240\346\270\270\346\210\217/Solution.py" @@ -0,0 +1,31 @@ +class Solution: + def ballGame(self, num: int, plate: List[str]) -> List[List[int]]: + def check(i, j, d): + k = num + while plate[i][j] != 'O': + if k == 0: + return False + if plate[i][j] == 'W': + d = (d + 3) % 4 + elif plate[i][j] == 'E': + d = (d + 1) % 4 + i, j = i + dirs[d], j + dirs[d + 1] + if not (0 <= i < m and 0 <= j < n): + return False + k -= 1 + return True + + dirs = (0, 1, 0, -1, 0) + m, n = len(plate), len(plate[0]) + ans = [] + for i in range(1, m - 1): + if plate[i][0] == '.' and check(i, 0, 0): + ans.append([i, 0]) + if plate[i][n - 1] == '.' and check(i, n - 1, 2): + ans.append([i, n - 1]) + for j in range(1, n - 1): + if plate[0][j] == '.' and check(0, j, 1): + ans.append([0, j]) + if plate[m - 1][j] == '.' and check(m - 1, j, 3): + ans.append([m - 1, j]) + return ans From d7c72d6a5dc643b9c23fdb29d264d5f551013660 Mon Sep 17 00:00:00 2001 From: thinkasany <480968828@qq.com> Date: Thu, 6 Apr 2023 11:33:29 +0800 Subject: [PATCH 4/6] feat: add solutions to lcp problem: No.06 --- .../README.md" | 12 ++++++++++++ .../Solution.ts" | 7 +++++++ 2 files changed, 19 insertions(+) create mode 100644 "lcp/LCP 06. \346\213\277\347\241\254\345\270\201/Solution.ts" diff --git "a/lcp/LCP 06. \346\213\277\347\241\254\345\270\201/README.md" "b/lcp/LCP 06. \346\213\277\347\241\254\345\270\201/README.md" index 707a0200e85d8..40f157d355561 100644 --- "a/lcp/LCP 06. \346\213\277\347\241\254\345\270\201/README.md" +++ "b/lcp/LCP 06. \346\213\277\347\241\254\345\270\201/README.md" @@ -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; +} +``` + ### **...** ``` diff --git "a/lcp/LCP 06. \346\213\277\347\241\254\345\270\201/Solution.ts" "b/lcp/LCP 06. \346\213\277\347\241\254\345\270\201/Solution.ts" new file mode 100644 index 0000000000000..0ef82440a05b5 --- /dev/null +++ "b/lcp/LCP 06. \346\213\277\347\241\254\345\270\201/Solution.ts" @@ -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; +} From ca21e275da4215c0361b1814c0b09e6ca42e8565 Mon Sep 17 00:00:00 2001 From: thinkasany <480968828@qq.com> Date: Thu, 6 Apr 2023 11:36:15 +0800 Subject: [PATCH 5/6] feat: update solutions to lcp problem: No.01, No.02 --- "lcp/LCP 01. \347\214\234\346\225\260\345\255\227/README.md" | 2 +- "lcp/LCP 01. \347\214\234\346\225\260\345\255\227/Solution.js" | 2 +- .../README.md" | 2 +- .../Solution.js" | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git "a/lcp/LCP 01. \347\214\234\346\225\260\345\255\227/README.md" "b/lcp/LCP 01. \347\214\234\346\225\260\345\255\227/README.md" index 8780e275d884a..067b148f09fef 100644 --- "a/lcp/LCP 01. \347\214\234\346\225\260\345\255\227/README.md" +++ "b/lcp/LCP 01. \347\214\234\346\225\260\345\255\227/README.md" @@ -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; }; diff --git "a/lcp/LCP 01. \347\214\234\346\225\260\345\255\227/Solution.js" "b/lcp/LCP 01. \347\214\234\346\225\260\345\255\227/Solution.js" index 931a8aaff2977..fd026bdfa6d2e 100644 --- "a/lcp/LCP 01. \347\214\234\346\225\260\345\255\227/Solution.js" +++ "b/lcp/LCP 01. \347\214\234\346\225\260\345\255\227/Solution.js" @@ -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; }; diff --git "a/lcp/LCP 02. \345\210\206\345\274\217\345\214\226\347\256\200/README.md" "b/lcp/LCP 02. \345\210\206\345\274\217\345\214\226\347\256\200/README.md" index 3f0ecbb1d3ac8..a8823d0e76728 100644 --- "a/lcp/LCP 02. \345\210\206\345\274\217\345\214\226\347\256\200/README.md" +++ "b/lcp/LCP 02. \345\210\206\345\274\217\345\214\226\347\256\200/README.md" @@ -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); diff --git "a/lcp/LCP 02. \345\210\206\345\274\217\345\214\226\347\256\200/Solution.js" "b/lcp/LCP 02. \345\210\206\345\274\217\345\214\226\347\256\200/Solution.js" index 1418dcfceeaad..bd9a7ee86b9bd 100644 --- "a/lcp/LCP 02. \345\210\206\345\274\217\345\214\226\347\256\200/Solution.js" +++ "b/lcp/LCP 02. \345\210\206\345\274\217\345\214\226\347\256\200/Solution.js" @@ -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); From 9fcd03470b854723daa90750b0b01992f7d0d490 Mon Sep 17 00:00:00 2001 From: thinkasany <480968828@qq.com> Date: Thu, 6 Apr 2023 11:58:17 +0800 Subject: [PATCH 6/6] style: resize document image size --- .../README.md" | 2 ++ .../README.md" | 4 ++-- .../README.md" | 4 ++-- .../README.md" | 6 +++--- .../README.md" | 10 +++++----- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git "a/lcp/LCP 57. \346\211\223\345\234\260\351\274\240/README.md" "b/lcp/LCP 57. \346\211\223\345\234\260\351\274\240/README.md" index c01b74e63499f..37ca7cda3add9 100644 --- "a/lcp/LCP 57. \346\211\223\345\234\260\351\274\240/README.md" +++ "b/lcp/LCP 57. \346\211\223\345\234\260\351\274\240/README.md" @@ -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)`,锤子的使用规则如下: diff --git "a/lcp/LCP 60. \345\212\233\346\211\243\346\263\241\346\263\241\351\276\231/README.md" "b/lcp/LCP 60. \345\212\233\346\211\243\346\263\241\346\263\241\351\276\231/README.md" index 8a3870bc22e03..968c690d927cf 100644 --- "a/lcp/LCP 60. \345\212\233\346\211\243\346\263\241\346\263\241\351\276\231/README.md" +++ "b/lcp/LCP 60. \345\212\233\346\211\243\346\263\241\346\263\241\351\276\231/README.md" @@ -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) +>
![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:** @@ -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) +>
![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:** diff --git "a/lcp/LCP 67. \350\243\205\351\245\260\346\240\221/README.md" "b/lcp/LCP 67. \350\243\205\351\245\260\346\240\221/README.md" index d08de8f039162..c1e35f1232d91 100644 --- "a/lcp/LCP 67. \350\243\205\351\245\260\346\240\221/README.md" +++ "b/lcp/LCP 67. \350\243\205\351\245\260\346\240\221/README.md" @@ -20,7 +20,7 @@ > 输出:`[7,-1,-1,5,null,null,6]` > > 解释:如下图所示, -> ![image.png](https://fastly.jsdelivr.net/gh/doocs/leetcode@main/lcp/LCP%2067.%20%E8%A3%85%E9%A5%B0%E6%A0%91/images/1663575757-yRLGaq-image.png) +>
**示例 2:** @@ -30,7 +30,7 @@ > 输出:`[3,-1,-1,1,null,null,7,-1,-1,null,-1,3,null,null,8,null,4]` > > 解释:如下图所示 -> ![image.png](https://fastly.jsdelivr.net/gh/doocs/leetcode@main/lcp/LCP%2067.%20%E8%A3%85%E9%A5%B0%E6%A0%91/images/1663577920-sjrAYH-image.png) +>
**提示:** diff --git "a/lcp/LCP 70. \346\262\231\345\234\260\346\262\273\347\220\206/README.md" "b/lcp/LCP 70. \346\262\231\345\234\260\346\262\273\347\220\206/README.md" index 17fad4564d58f..32bf21b09d48a 100644 --- "a/lcp/LCP 70. \346\262\231\345\234\260\346\262\273\347\220\206/README.md" +++ "b/lcp/LCP 70. \346\262\231\345\234\260\346\262\273\347\220\206/README.md" @@ -13,7 +13,7 @@ > 如下图所示,(1,1)和(2,2)相邻,(3,2)和(3,3)相邻;(2,2)和(3,3)不相邻,因为它们没有共用边。 - 若至少有两片绿地与同一片沙地相邻,则这片沙地也会转化为绿地 - 转化为绿地的区域会影响其相邻的沙地 - ![image.png](https://fastly.jsdelivr.net/gh/doocs/leetcode@main/lcp/LCP%2070.%20%E6%B2%99%E5%9C%B0%E6%B2%BB%E7%90%86/images/1662692397-VlvErS-image.png) +
现要将一片边长为 `size`  的沙地全部转化为绿地,请找到任意一种初始指定 **最少** 数量子区域种植沙柳的方案,并返回所有初始种植沙柳树的绿地坐标。 @@ -25,7 +25,7 @@ > 指定所示的 5 个子区域为绿地。 > 相邻至少两片绿地的 (2,2),(3,2) 和 (3,4) 演变为绿地。 > 相邻两片绿地的 (3,3) 演变为绿地。 -> ![image.png](https://fastly.jsdelivr.net/gh/doocs/leetcode@main/lcp/LCP%2070.%20%E6%B2%99%E5%9C%B0%E6%B2%BB%E7%90%86/images/1662692503-ncjywh-image.png) +>
**示例 2:** @@ -34,7 +34,7 @@ > 解释:如下图所示: > 指定所示的 3 个子区域为绿地。 > 相邻三片绿地的 (2,2) 演变为绿地。 -> ![image.png](https://fastly.jsdelivr.net/gh/doocs/leetcode@main/lcp/LCP%2070.%20%E6%B2%99%E5%9C%B0%E6%B2%BB%E7%90%86/images/1662692507-mgFXRj-image.png) +>
**提示:** diff --git "a/lcp/LCP 71. \351\233\206\346\260\264\345\231\250/README.md" "b/lcp/LCP 71. \351\233\206\346\260\264\345\231\250/README.md" index 0820e2a41565b..8903b8b00b1bd 100644 --- "a/lcp/LCP 71. \351\233\206\346\260\264\345\231\250/README.md" +++ "b/lcp/LCP 71. \351\233\206\346\260\264\345\231\250/README.md" @@ -9,7 +9,7 @@ - `'l'`表示向左倾斜的隔板(即从左上到右下); - `'r'`表示向右倾斜的隔板(即从左下到右上); - `'.'` 表示此位置没有隔板 - ![image.png](https://fastly.jsdelivr.net/gh/doocs/leetcode@main/lcp/LCP%2071.%20%E9%9B%86%E6%B0%B4%E5%99%A8/images/1664424667-wMnPja-image.png) +
已知当隔板构成存储容器可以存水,每个方格代表的蓄水量为 `2`。集水器初始浸泡在水中,除内部密闭空间外,所有位置均被水填满。 现将其从水中竖直向上取出,请返回集水器最终的蓄水量。 @@ -26,7 +26,7 @@ > 输出:`18` > > 解释:如下图所示,由于空气会穿过隔板,因此红框区域没有水 -> ![image.png](https://fastly.jsdelivr.net/gh/doocs/leetcode@main/lcp/LCP%2071.%20%E9%9B%86%E6%B0%B4%E5%99%A8/images/1664436239-eyYxeP-image.png) +>
**示例 2:** @@ -35,7 +35,7 @@ > 输出:`18` > > 解释:如图所示。由于红框右侧未闭合,因此多余的水会从该处流走。 -> ![image.png](https://fastly.jsdelivr.net/gh/doocs/leetcode@main/lcp/LCP%2071.%20%E9%9B%86%E6%B0%B4%E5%99%A8/images/1664436082-SibVMv-image.png) +>
**示例 3:** @@ -44,7 +44,7 @@ > 输出:`6` > > 解释:如图所示。 -> ![image.png](https://fastly.jsdelivr.net/gh/doocs/leetcode@main/lcp/LCP%2071.%20%E9%9B%86%E6%B0%B4%E5%99%A8/images/1664424855-dwpUHO-image.png) +>
**示例 4:** @@ -54,7 +54,7 @@ > 输出:`30` > > 解释:如下图所示。由于中间为内部密闭空间,无法蓄水。 -> ![image.png](https://fastly.jsdelivr.net/gh/doocs/leetcode@main/lcp/LCP%2071.%20%E9%9B%86%E6%B0%B4%E5%99%A8/images/1664424894-mClEXh-image.png) +>
**提示**: