Skip to content

Commit d05b667

Browse files
authored
update: 添加问题“1128.等价多米诺骨牌对的数量”的代码和题解(#913)
* archive: 2025.04.30 - 实验室周报+毕设月报 Signed-off-by: LetMeFly666 <[email protected]> * WA: C++ + init codes (#911) Signed-off-by: LetMeFly666 <[email protected]> * WA: C++ + debug (#911) Signed-off-by: LetMeFly666 <[email protected]> * WA: C++ + debug (#911) Signed-off-by: LetMeFly666 <[email protected]> * WA: C++ + debug (#911) Signed-off-by: LetMeFly666 <[email protected]> * WA: C++ + debug (#911) Signed-off-by: LetMeFly666 <[email protected]> * WA: C++ - before refactor (#911) Signed-off-by: LetMeFly666 <[email protected]> * AC: C++(#911) Signed-off-by: LetMeFly666 <[email protected]> * words: en+jp (#911) Signed-off-by: LetMeFly666 <[email protected]> * AC: py (#911) Signed-off-by: LetMeFly666 <[email protected]> * AC: CPP+Java (#911) Signed-off-by: LetMeFly666 <[email protected]> * AC: Go (#911) Signed-off-by: LetMeFly666 <[email protected]> * update: 添加问题“1128.等价多米诺骨牌对的数量”的代码和题解(#913) Signed-off-by: LetMeFly666 <[email protected]> --------- Signed-off-by: LetMeFly666 <[email protected]>
1 parent 0b5a1ed commit d05b667

14 files changed

+684
-2
lines changed

.changelog

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
PS F:\OtherApps\Program\Git\Store\Store20_LeetCode> git pull origin master
2+
remote: Enumerating objects: 79, done.
3+
remote: Counting objects: 100% (36/36), done.
4+
remote: Compressing objects: 100% (20/20), done.
5+
remote: Total 79 (delta 21), reused 21 (delta 16), pack-reused 43 (from 1)
6+
Unpacking objects: 100% (79/79), 405.06 KiB | 52.00 KiB/s, done.
7+
From github.com:LetMeFly666/LeetCode
8+
* branch master -> FETCH_HEAD
9+
8783deb45b0..0b5a1edae4c master -> origin/master
10+
Updating 8783deb45b0..0b5a1edae4c
11+
Fast-forward
12+
...295-find-numbers-with-even-number-of-digits.cpp | 29 ++
13+
...1295-find-numbers-with-even-number-of-digits.go | 19 +
14+
...95-find-numbers-with-even-number-of-digits.java | 25 ++
15+
...1295-find-numbers-with-even-number-of-digits.py | 11 +
16+
...-numbers-with-even-number-of-digits_method2.cpp | 23 +
17+
Codes/1399-count-largest-group.cpp | 30 ++
18+
Codes/1399-count-largest-group.go | 26 ++
19+
Codes/1399-count-largest-group.java | 30 ++
20+
Codes/1399-count-largest-group.py | 17 +
21+
...2302-count-subarrays-with-score-less-than-k.cpp | 56 +++
22+
.../2302-count-subarrays-with-score-less-than-k.go | 21 +
23+
...302-count-subarrays-with-score-less-than-k.java | 19 +
24+
.../2302-count-subarrays-with-score-less-than-k.py | 18 +
25+
...-subarrays-with-score-less-than-k_notSuffix.cpp | 26 ++
26+
.../2799-count-complete-subarrays-in-an-array.cpp | 32 ++
27+
Codes/2799-count-complete-subarrays-in-an-array.go | 29 ++
28+
.../2799-count-complete-subarrays-in-an-array.java | 34 ++
29+
Codes/2799-count-complete-subarrays-in-an-array.py | 23 +
30+
...-where-max-element-appears-at-least-k-times.cpp | 30 ++
31+
...s-where-max-element-appears-at-least-k-times.go | 27 ++
32+
...where-max-element-appears-at-least-k-times.java | 27 ++
33+
...s-where-max-element-appears-at-least-k-times.py | 19 +
34+
...-subarrays-of-length-three-with-a-condition.cpp | 20 +
35+
...t-subarrays-of-length-three-with-a-condition.go | 17 +
36+
...subarrays-of-length-three-with-a-condition.java | 17 +
37+
...t-subarrays-of-length-three-with-a-condition.py | 11 +
38+
README.md | 9 +-
39+
Solutions/LeetCode 1295.统计位数为偶数的数字.md | 210 +++++++++
40+
Solutions/LeetCode 1399.统计最大组的数目.md | 192 ++++++++
41+
.../LeetCode 2302.统计得分小于K的子数组数目.md | 181 ++++++++
42+
Solutions/LeetCode 2799.统计完全子数组的数目.md | 204 +++++++++
43+
...eetCode 2962.统计最大元素出现至少K次的子数组.md | 182 ++++++++
44+
...eetCode 3392.统计符合条件长度为3的子数组数目.md | 145 ++++++
45+
Solutions/Other-English-LearningNotes-SomeWords.md | 26 +-
46+
Solutions/Other-Japanese-LearningNotes.md | 17 +-
47+
newSolution.py | 4 +-
48+
tryGoPy/MGJW/lastWeek/05/chat.md | 44 ++
49+
.../{thisWeek => lastWeek/05}/encryptAndDecrypt.py | 0
50+
.../{thisWeek => lastWeek/05}/testForLength.py | 0
51+
.../{thisWeek => lastWeek/05}/testForLength2.py | 0
52+
.../{thisWeek => lastWeek/05}/testForLength3.py | 0
53+
.../{thisWeek => lastWeek/05}/testForLength4.py | 0
54+
tryGoPy/MGJW/lastWeek/05/周报.md | 416 +++++++++++++++++
55+
tryGoPy/MGJW/temp/周报.md | 22 -
56+
tryGoPy/MGJW/{temp => thisWeek}/README | 0
57+
tryGoPy/MGJW/thisWeek/chat.md | 47 +-
58+
tryGoPy/MGJW/thisWeek/周报.md | 499 +++++----------------
59+
47 files changed, 2397 insertions(+), 437 deletions(-)
60+
create mode 100644 Codes/1295-find-numbers-with-even-number-of-digits.cpp
61+
create mode 100644 Codes/1295-find-numbers-with-even-number-of-digits.go
62+
create mode 100644 Codes/1295-find-numbers-with-even-number-of-digits.java
63+
create mode 100644 Codes/1295-find-numbers-with-even-number-of-digits.py
64+
create mode 100644 Codes/1295-find-numbers-with-even-number-of-digits_method2.cpp
65+
create mode 100644 Codes/1399-count-largest-group.cpp
66+
create mode 100644 Codes/1399-count-largest-group.go
67+
create mode 100644 Codes/1399-count-largest-group.java
68+
create mode 100644 Codes/1399-count-largest-group.py
69+
create mode 100644 Codes/2302-count-subarrays-with-score-less-than-k.cpp
70+
create mode 100644 Codes/2302-count-subarrays-with-score-less-than-k.go
71+
create mode 100644 Codes/2302-count-subarrays-with-score-less-than-k.java
72+
create mode 100644 Codes/2302-count-subarrays-with-score-less-than-k.py
73+
create mode 100644 Codes/2302-count-subarrays-with-score-less-than-k_notSuffix.cpp
74+
create mode 100644 Codes/2799-count-complete-subarrays-in-an-array.cpp
75+
create mode 100644 Codes/2799-count-complete-subarrays-in-an-array.go
76+
create mode 100644 Codes/2799-count-complete-subarrays-in-an-array.java
77+
create mode 100644 Codes/2799-count-complete-subarrays-in-an-array.py
78+
create mode 100644 Codes/2962-count-subarrays-where-max-element-appears-at-least-k-times.cpp
79+
create mode 100644 Codes/2962-count-subarrays-where-max-element-appears-at-least-k-times.go
80+
create mode 100644 Codes/2962-count-subarrays-where-max-element-appears-at-least-k-times.java
81+
create mode 100644 Codes/2962-count-subarrays-where-max-element-appears-at-least-k-times.py
82+
create mode 100644 Codes/3392-count-subarrays-of-length-three-with-a-condition.cpp
83+
create mode 100644 Codes/3392-count-subarrays-of-length-three-with-a-condition.go
84+
create mode 100644 Codes/3392-count-subarrays-of-length-three-with-a-condition.java
85+
create mode 100644 Codes/3392-count-subarrays-of-length-three-with-a-condition.py
86+
create mode 100644 Solutions/LeetCode 1295.统计位数为偶数的数字.md
87+
create mode 100644 Solutions/LeetCode 1399.统计最大组的数目.md
88+
create mode 100644 Solutions/LeetCode 2302.统计得分小于K的子数组数目.md
89+
create mode 100644 Solutions/LeetCode 2799.统计完全子数组的数目.md
90+
create mode 100644 Solutions/LeetCode 2962.统计最大元素出现至少K次的子数组.md
91+
create mode 100644 Solutions/LeetCode 3392.统计符合条件长度为3的子数组数目.md
92+
create mode 100644 tryGoPy/MGJW/lastWeek/05/chat.md
93+
rename tryGoPy/MGJW/{thisWeek => lastWeek/05}/encryptAndDecrypt.py (100%)
94+
rename tryGoPy/MGJW/{thisWeek => lastWeek/05}/testForLength.py (100%)
95+
rename tryGoPy/MGJW/{thisWeek => lastWeek/05}/testForLength2.py (100%)
96+
rename tryGoPy/MGJW/{thisWeek => lastWeek/05}/testForLength3.py (100%)
97+
rename tryGoPy/MGJW/{thisWeek => lastWeek/05}/testForLength4.py (100%)
98+
create mode 100644 tryGoPy/MGJW/lastWeek/05/周报.md
99+
delete mode 100644 tryGoPy/MGJW/temp/周报.md
100+
rename tryGoPy/MGJW/{temp => thisWeek}/README (100%)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-05-04 14:26:01
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-05-04 15:02:06
6+
*/
7+
#if defined(_WIN32) || defined(__APPLE__)
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
class Solution {
12+
private:
13+
inline int pair2int(vector<int>& v) {
14+
if (v[0] > v[1]) {
15+
return (v[1] - 1) * 9 + (v[0] - 1);
16+
}
17+
return (v[0] - 1) * 9 + (v[1] - 1);
18+
}
19+
public:
20+
int numEquivDominoPairs(vector<vector<int>>& dominoes) {
21+
int times[81] = {0};
22+
for (vector<int>& v : dominoes) {
23+
times[pair2int(v)]++;
24+
}
25+
int ans = 0;
26+
for (int i = 0; i < 81; i++) {
27+
ans += times[i] * (times[i] - 1) / 2;
28+
}
29+
return ans;
30+
}
31+
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-05-04 14:26:18
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-05-04 16:18:34
6+
*/
7+
package main
8+
9+
func numEquivDominoPairs(dominoes [][]int) (ans int) {
10+
times := make([]int, 81)
11+
for _, d := range dominoes {
12+
var v int
13+
if d[0] < d[1] {
14+
v = (d[0] - 1) * 9 + d[1] - 1
15+
} else {
16+
v = (d[1] - 1) * 9 + d[0] - 1
17+
}
18+
ans += times[v]
19+
times[v]++
20+
}
21+
return
22+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-05-04 14:26:15
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-05-04 16:15:28
6+
*/
7+
class Solution {
8+
public int numEquivDominoPairs(int[][] dominoes) {
9+
int[] times = new int[81];
10+
int ans = 0;
11+
for (int[] d : dominoes) {
12+
ans += times[d[0] < d[1] ? (d[0] - 1) * 9 + d[1] - 1 : (d[1] - 1) * 9 + d[0] - 1]++;
13+
}
14+
return ans;
15+
}
16+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'''
2+
Author: LetMeFly
3+
Date: 2025-05-04 14:26:12
4+
LastEditors: LetMeFly.xyz
5+
LastEditTime: 2025-05-04 16:10:15
6+
'''
7+
from typing import List
8+
9+
class Solution:
10+
def numEquivDominoPairs(self, dominoes: List[List[int]]) -> int:
11+
times = [0] * 81
12+
ans = 0
13+
for a, b in dominoes:
14+
v = (a - 1) * 9 + (b - 1) if a < b else (b - 1) * 9 + (a - 1)
15+
ans += times[v]
16+
times[v] += 1
17+
return ans
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-05-04 16:12:00
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-05-04 16:13:46
6+
*/
7+
#if defined(_WIN32) || defined(__APPLE__)
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
class Solution {
12+
public:
13+
int numEquivDominoPairs(vector<vector<int>>& dominoes) {
14+
int times[81] = {0} ;
15+
int ans = 0;
16+
for (vector<int>& d : dominoes) {
17+
ans += times[d[0] < d[1] ? (d[0] - 1) * 9 + d[1] - 1 : (d[1] - 1) * 9 + d[0] - 1]++;
18+
}
19+
return ans;
20+
}
21+
};

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@
476476
|1106.解析布尔表达式|困难|<a href="https://leetcode.cn/problems/parsing-a-boolean-expression/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2022/11/05/LeetCode%201106.%E8%A7%A3%E6%9E%90%E5%B8%83%E5%B0%94%E8%A1%A8%E8%BE%BE%E5%BC%8F/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/127700117" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/parsing-a-boolean-expression/solutions/1949455/letmefly-1106jie-xi-bu-er-biao-da-shi-by-9var/" target="_blank">LeetCode题解</a>|
477477
|1110.删点成林|中等|<a href="https://leetcode.cn/problems/delete-nodes-and-return-forest/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2023/05/30/LeetCode%201110.%E5%88%A0%E7%82%B9%E6%88%90%E6%9E%97/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/130941100" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/delete-nodes-and-return-forest/solutions/2289169/letmefly-1110shan-dian-cheng-lin-by-tisf-esap/" target="_blank">LeetCode题解</a>|
478478
|1123.最深叶节点的最近公共祖先|中等|<a href="https://leetcode.cn/problems/lowest-common-ancestor-of-deepest-leaves/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2023/09/06/LeetCode%201123.%E6%9C%80%E6%B7%B1%E5%8F%B6%E8%8A%82%E7%82%B9%E7%9A%84%E6%9C%80%E8%BF%91%E5%85%AC%E5%85%B1%E7%A5%96%E5%85%88/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/132725441" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/lowest-common-ancestor-of-deepest-leaves/solutions/2430280/letmefly-1123zui-shen-xie-jie-dian-de-zu-mwbj/" target="_blank">LeetCode题解</a>|
479+
|1128.等价多米诺骨牌对的数量|简单|<a href="https://leetcode.cn/problems/number-of-equivalent-domino-pairs/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/05/04/LeetCode%201128.%E7%AD%89%E4%BB%B7%E5%A4%9A%E7%B1%B3%E8%AF%BA%E9%AA%A8%E7%89%8C%E5%AF%B9%E7%9A%84%E6%95%B0%E9%87%8F/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/147700894" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/number-of-equivalent-domino-pairs/solutions/3668617/letmefly-1128deng-jie-duo-mi-nuo-gu-pai-wfo2a/" target="_blank">LeetCode题解</a>|
479480
|1138.字母板上的路径|中等|<a href="https://leetcode.cn/problems/alphabet-board-path/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2023/02/12/LeetCode%201138.%E5%AD%97%E6%AF%8D%E6%9D%BF%E4%B8%8A%E7%9A%84%E8%B7%AF%E5%BE%84/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/128992281" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/alphabet-board-path/solutions/2106765/letmefly-1138zi-mu-ban-shang-de-lu-jing-70pdg/" target="_blank">LeetCode题解</a>|
480481
|1144.递减元素使数组呈锯齿状|中等|<a href="https://leetcode.cn/problems/decrease-elements-to-make-array-zigzag/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2023/02/27/LeetCode%201144.%E9%80%92%E5%87%8F%E5%85%83%E7%B4%A0%E4%BD%BF%E6%95%B0%E7%BB%84%E5%91%88%E9%94%AF%E9%BD%BF%E7%8A%B6/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/129235998" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/decrease-elements-to-make-array-zigzag/solutions/2135691/letmefly-1144di-jian-yuan-su-shi-shu-zu-4h459/" target="_blank">LeetCode题解</a>|
481482
|1146.快照数组|中等|<a href="https://leetcode.cn/problems/snapshot-array/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/04/26/LeetCode%201146.%E5%BF%AB%E7%85%A7%E6%95%B0%E7%BB%84/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/138214080" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/snapshot-array/solutions/2756531/letmefly-1146kuai-zhao-shu-zu-er-fen-cha-p2wq/" target="_blank">LeetCode题解</a>|

0 commit comments

Comments
 (0)