Skip to content

Commit 3422ef3

Browse files
authored
feat: add new lc problems (#2097)
1 parent 91f81d5 commit 3422ef3

File tree

6 files changed

+190
-22
lines changed

6 files changed

+190
-22
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# [2964. Number of Divisible Triplet Sums](https://leetcode.cn/problems/number-of-divisible-triplet-sums)
2+
3+
[English Version](/solution/2900-2999/2964.Number%20of%20Divisible%20Triplet%20Sums/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
Given a <strong>0-indexed</strong> integer array <code>nums</code> and an integer <code>d</code>, return <em>the number of triplets</em> <code>(i, j, k)</code> <em>such that</em> <code>i &lt; j &lt; k</code> <em>and</em> <code>(nums[i] + nums[j] + nums[k]) % d == 0</code>.
10+
11+
<p>&nbsp;</p>
12+
<p><strong class="example">Example 1:</strong></p>
13+
14+
<pre>
15+
<strong>Input:</strong> nums = [3,3,4,7,8], d = 5
16+
<strong>Output:</strong> 3
17+
<strong>Explanation:</strong> The triplets which are divisible by 5 are: (0, 1, 2), (0, 2, 4), (1, 2, 4).
18+
It can be shown that no other triplet is divisible by 5. Hence, the answer is 3.
19+
</pre>
20+
21+
<p><strong class="example">Example 2:</strong></p>
22+
23+
<pre>
24+
<strong>Input:</strong> nums = [3,3,3,3], d = 3
25+
<strong>Output:</strong> 4
26+
<strong>Explanation:</strong> Any triplet chosen here has a sum of 9, which is divisible by 3. Hence, the answer is the total number of triplets which is 4.
27+
</pre>
28+
29+
<p><strong class="example">Example 3:</strong></p>
30+
31+
<pre>
32+
<strong>Input:</strong> nums = [3,3,3,3], d = 6
33+
<strong>Output:</strong> 0
34+
<strong>Explanation:</strong> Any triplet chosen here has a sum of 9, which is not divisible by 6. Hence, the answer is 0.
35+
</pre>
36+
37+
<p>&nbsp;</p>
38+
<p><strong>Constraints:</strong></p>
39+
40+
<ul>
41+
<li><code>1 &lt;= nums.length &lt;= 1000</code></li>
42+
<li><code>1 &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
43+
<li><code>1 &lt;= d &lt;= 10<sup>9</sup></code></li>
44+
</ul>
45+
46+
## 解法
47+
48+
<!-- 这里可写通用的实现逻辑 -->
49+
50+
<!-- tabs:start -->
51+
52+
### **Python3**
53+
54+
<!-- 这里可写当前语言的特殊实现逻辑 -->
55+
56+
```python
57+
58+
```
59+
60+
### **Java**
61+
62+
<!-- 这里可写当前语言的特殊实现逻辑 -->
63+
64+
```java
65+
66+
```
67+
68+
### **C++**
69+
70+
```cpp
71+
72+
```
73+
74+
### **Go**
75+
76+
```go
77+
78+
```
79+
80+
### **...**
81+
82+
```
83+
84+
```
85+
86+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# [2964. Number of Divisible Triplet Sums](https://leetcode.com/problems/number-of-divisible-triplet-sums)
2+
3+
[中文文档](/solution/2900-2999/2964.Number%20of%20Divisible%20Triplet%20Sums/README.md)
4+
5+
## Description
6+
7+
Given a <strong>0-indexed</strong> integer array <code>nums</code> and an integer <code>d</code>, return <em>the number of triplets</em> <code>(i, j, k)</code> <em>such that</em> <code>i &lt; j &lt; k</code> <em>and</em> <code>(nums[i] + nums[j] + nums[k]) % d == 0</code>.
8+
9+
<p>&nbsp;</p>
10+
<p><strong class="example">Example 1:</strong></p>
11+
12+
<pre>
13+
<strong>Input:</strong> nums = [3,3,4,7,8], d = 5
14+
<strong>Output:</strong> 3
15+
<strong>Explanation:</strong> The triplets which are divisible by 5 are: (0, 1, 2), (0, 2, 4), (1, 2, 4).
16+
It can be shown that no other triplet is divisible by 5. Hence, the answer is 3.
17+
</pre>
18+
19+
<p><strong class="example">Example 2:</strong></p>
20+
21+
<pre>
22+
<strong>Input:</strong> nums = [3,3,3,3], d = 3
23+
<strong>Output:</strong> 4
24+
<strong>Explanation:</strong> Any triplet chosen here has a sum of 9, which is divisible by 3. Hence, the answer is the total number of triplets which is 4.
25+
</pre>
26+
27+
<p><strong class="example">Example 3:</strong></p>
28+
29+
<pre>
30+
<strong>Input:</strong> nums = [3,3,3,3], d = 6
31+
<strong>Output:</strong> 0
32+
<strong>Explanation:</strong> Any triplet chosen here has a sum of 9, which is not divisible by 6. Hence, the answer is 0.
33+
</pre>
34+
35+
<p>&nbsp;</p>
36+
<p><strong>Constraints:</strong></p>
37+
38+
<ul>
39+
<li><code>1 &lt;= nums.length &lt;= 1000</code></li>
40+
<li><code>1 &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
41+
<li><code>1 &lt;= d &lt;= 10<sup>9</sup></code></li>
42+
</ul>
43+
44+
## Solutions
45+
46+
<!-- tabs:start -->
47+
48+
### **Python3**
49+
50+
```python
51+
52+
```
53+
54+
### **Java**
55+
56+
```java
57+
58+
```
59+
60+
### **C++**
61+
62+
```cpp
63+
64+
```
65+
66+
### **Go**
67+
68+
```go
69+
70+
```
71+
72+
### **...**
73+
74+
```
75+
76+
```
77+
78+
<!-- tabs:end -->

solution/README.md

+12-11
Original file line numberDiff line numberDiff line change
@@ -2962,18 +2962,19 @@
29622962
| 2949 | [统计美丽子字符串 II](/solution/2900-2999/2949.Count%20Beautiful%20Substrings%20II/README.md) | `哈希表`,`数学`,`字符串`,`数论`,`前缀和` | 困难 | 第 373 场周赛 |
29632963
| 2950 | [可整除子串的数量](/solution/2900-2999/2950.Number%20of%20Divisible%20Substrings/README.md) | `哈希表`,`字符串`,`计数` | 中等 | 🔒 |
29642964
| 2951 | [找出峰值](/solution/2900-2999/2951.Find%20the%20Peaks/README.md) | `数组`,`枚举` | 简单 | 第 374 场周赛 |
2965-
| 2952 | [需要添加的硬币的最小数量](/solution/2900-2999/2952.Minimum%20Number%20of%20Coins%20to%20be%20Added/README.md) | `贪心`,`数组`,`排序` | 困难 | 第 374 场周赛 |
2966-
| 2953 | [统计完全子字符串](/solution/2900-2999/2953.Count%20Complete%20Substrings/README.md) | `哈希表`,`字符串`,`滑动窗口` | 中等 | 第 374 场周赛 |
2965+
| 2952 | [需要添加的硬币的最小数量](/solution/2900-2999/2952.Minimum%20Number%20of%20Coins%20to%20be%20Added/README.md) | `贪心`,`数组`,`排序` | 中等 | 第 374 场周赛 |
2966+
| 2953 | [统计完全子字符串](/solution/2900-2999/2953.Count%20Complete%20Substrings/README.md) | `哈希表`,`字符串`,`滑动窗口` | 困难 | 第 374 场周赛 |
29672967
| 2954 | [统计感冒序列的数目](/solution/2900-2999/2954.Count%20the%20Number%20of%20Infection%20Sequences/README.md) | `数组`,`数学`,`组合数学` | 困难 | 第 374 场周赛 |
2968-
| 2955 | [Number of Same-End Substrings](/solution/2900-2999/2955.Number%20of%20Same-End%20Substrings/README.md) | | 中等 | 🔒 |
2969-
| 2956 | [找到两个数组中的公共元素](/solution/2900-2999/2956.Find%20Common%20Elements%20Between%20Two%20Arrays/README.md) | | 简单 | 第 119 场双周赛 |
2970-
| 2957 | [消除相邻近似相等字符](/solution/2900-2999/2957.Remove%20Adjacent%20Almost-Equal%20Characters/README.md) | | 中等 | 第 119 场双周赛 |
2971-
| 2958 | [最多 K 个重复元素的最长子数组](/solution/2900-2999/2958.Length%20of%20Longest%20Subarray%20With%20at%20Most%20K%20Frequency/README.md) | | 中等 | 第 119 场双周赛 |
2972-
| 2959 | [关闭分部的可行集合数目](/solution/2900-2999/2959.Number%20of%20Possible%20Sets%20of%20Closing%20Branches/README.md) | | 困难 | 第 119 场双周赛 |
2973-
| 2960 | [统计已测试设备](/solution/2900-2999/2960.Count%20Tested%20Devices%20After%20Test%20Operations/README.md) | | 简单 | 第 375 场周赛 |
2974-
| 2961 | [双模幂运算](/solution/2900-2999/2961.Double%20Modular%20Exponentiation/README.md) | | 中等 | 第 375 场周赛 |
2975-
| 2962 | [统计最大元素出现至少 K 次的子数组](/solution/2900-2999/2962.Count%20Subarrays%20Where%20Max%20Element%20Appears%20at%20Least%20K%20Times/README.md) | | 中等 | 第 375 场周赛 |
2976-
| 2963 | [统计好分割方案的数目](/solution/2900-2999/2963.Count%20the%20Number%20of%20Good%20Partitions/README.md) | | 困难 | 第 375 场周赛 |
2968+
| 2955 | [Number of Same-End Substrings](/solution/2900-2999/2955.Number%20of%20Same-End%20Substrings/README.md) | `数组`,`哈希表`,`字符串`,`计数`,`前缀和` | 中等 | 🔒 |
2969+
| 2956 | [找到两个数组中的公共元素](/solution/2900-2999/2956.Find%20Common%20Elements%20Between%20Two%20Arrays/README.md) | `数组`,`哈希表` | 简单 | 第 119 场双周赛 |
2970+
| 2957 | [消除相邻近似相等字符](/solution/2900-2999/2957.Remove%20Adjacent%20Almost-Equal%20Characters/README.md) | `贪心`,`字符串`,`动态规划` | 中等 | 第 119 场双周赛 |
2971+
| 2958 | [最多 K 个重复元素的最长子数组](/solution/2900-2999/2958.Length%20of%20Longest%20Subarray%20With%20at%20Most%20K%20Frequency/README.md) | `数组`,`哈希表`,`滑动窗口` | 中等 | 第 119 场双周赛 |
2972+
| 2959 | [关闭分部的可行集合数目](/solution/2900-2999/2959.Number%20of%20Possible%20Sets%20of%20Closing%20Branches/README.md) | `位运算`,`图`,`枚举`,`最短路`,`堆(优先队列)` | 困难 | 第 119 场双周赛 |
2973+
| 2960 | [统计已测试设备](/solution/2900-2999/2960.Count%20Tested%20Devices%20After%20Test%20Operations/README.md) | `数组`,`模拟` | 简单 | 第 375 场周赛 |
2974+
| 2961 | [双模幂运算](/solution/2900-2999/2961.Double%20Modular%20Exponentiation/README.md) | `数组`,`数学`,`模拟` | 中等 | 第 375 场周赛 |
2975+
| 2962 | [统计最大元素出现至少 K 次的子数组](/solution/2900-2999/2962.Count%20Subarrays%20Where%20Max%20Element%20Appears%20at%20Least%20K%20Times/README.md) | `数组`,`滑动窗口` | 中等 | 第 375 场周赛 |
2976+
| 2963 | [统计好分割方案的数目](/solution/2900-2999/2963.Count%20the%20Number%20of%20Good%20Partitions/README.md) | `数组`,`哈希表`,`数学`,`组合数学` | 困难 | 第 375 场周赛 |
2977+
| 2964 | [Number of Divisible Triplet Sums](/solution/2900-2999/2964.Number%20of%20Divisible%20Triplet%20Sums/README.md) | | 中等 | 🔒 |
29772978

29782979
## 版权
29792980

solution/README_EN.md

+12-11
Original file line numberDiff line numberDiff line change
@@ -2960,18 +2960,19 @@ Press <kbd>Control</kbd> + <kbd>F</kbd>(or <kbd>Command</kbd> + <kbd>F</kbd> on
29602960
| 2949 | [Count Beautiful Substrings II](/solution/2900-2999/2949.Count%20Beautiful%20Substrings%20II/README_EN.md) | `Hash Table`,`Math`,`String`,`Number Theory`,`Prefix Sum` | Hard | Weekly Contest 373 |
29612961
| 2950 | [Number of Divisible Substrings](/solution/2900-2999/2950.Number%20of%20Divisible%20Substrings/README_EN.md) | `Hash Table`,`String`,`Counting` | Medium | 🔒 |
29622962
| 2951 | [Find the Peaks](/solution/2900-2999/2951.Find%20the%20Peaks/README_EN.md) | `Array`,`Enumeration` | Easy | Weekly Contest 374 |
2963-
| 2952 | [Minimum Number of Coins to be Added](/solution/2900-2999/2952.Minimum%20Number%20of%20Coins%20to%20be%20Added/README_EN.md) | `Greedy`,`Array`,`Sorting` | Hard | Weekly Contest 374 |
2964-
| 2953 | [Count Complete Substrings](/solution/2900-2999/2953.Count%20Complete%20Substrings/README_EN.md) | `Hash Table`,`String`,`Sliding Window` | Medium | Weekly Contest 374 |
2963+
| 2952 | [Minimum Number of Coins to be Added](/solution/2900-2999/2952.Minimum%20Number%20of%20Coins%20to%20be%20Added/README_EN.md) | `Greedy`,`Array`,`Sorting` | Medium | Weekly Contest 374 |
2964+
| 2953 | [Count Complete Substrings](/solution/2900-2999/2953.Count%20Complete%20Substrings/README_EN.md) | `Hash Table`,`String`,`Sliding Window` | Hard | Weekly Contest 374 |
29652965
| 2954 | [Count the Number of Infection Sequences](/solution/2900-2999/2954.Count%20the%20Number%20of%20Infection%20Sequences/README_EN.md) | `Array`,`Math`,`Combinatorics` | Hard | Weekly Contest 374 |
2966-
| 2955 | [Number of Same-End Substrings](/solution/2900-2999/2955.Number%20of%20Same-End%20Substrings/README_EN.md) | | Medium | 🔒 |
2967-
| 2956 | [Find Common Elements Between Two Arrays](/solution/2900-2999/2956.Find%20Common%20Elements%20Between%20Two%20Arrays/README_EN.md) | | Easy | Biweekly Contest 119 |
2968-
| 2957 | [Remove Adjacent Almost-Equal Characters](/solution/2900-2999/2957.Remove%20Adjacent%20Almost-Equal%20Characters/README_EN.md) | | Medium | Biweekly Contest 119 |
2969-
| 2958 | [Length of Longest Subarray With at Most K Frequency](/solution/2900-2999/2958.Length%20of%20Longest%20Subarray%20With%20at%20Most%20K%20Frequency/README_EN.md) | | Medium | Biweekly Contest 119 |
2970-
| 2959 | [Number of Possible Sets of Closing Branches](/solution/2900-2999/2959.Number%20of%20Possible%20Sets%20of%20Closing%20Branches/README_EN.md) | | Hard | Biweekly Contest 119 |
2971-
| 2960 | [Count Tested Devices After Test Operations](/solution/2900-2999/2960.Count%20Tested%20Devices%20After%20Test%20Operations/README_EN.md) | | Easy | Weekly Contest 375 |
2972-
| 2961 | [Double Modular Exponentiation](/solution/2900-2999/2961.Double%20Modular%20Exponentiation/README_EN.md) | | Medium | Weekly Contest 375 |
2973-
| 2962 | [Count Subarrays Where Max Element Appears at Least K Times](/solution/2900-2999/2962.Count%20Subarrays%20Where%20Max%20Element%20Appears%20at%20Least%20K%20Times/README_EN.md) | | Medium | Weekly Contest 375 |
2974-
| 2963 | [Count the Number of Good Partitions](/solution/2900-2999/2963.Count%20the%20Number%20of%20Good%20Partitions/README_EN.md) | | Hard | Weekly Contest 375 |
2966+
| 2955 | [Number of Same-End Substrings](/solution/2900-2999/2955.Number%20of%20Same-End%20Substrings/README_EN.md) | `Array`,`Hash Table`,`String`,`Counting`,`Prefix Sum` | Medium | 🔒 |
2967+
| 2956 | [Find Common Elements Between Two Arrays](/solution/2900-2999/2956.Find%20Common%20Elements%20Between%20Two%20Arrays/README_EN.md) | `Array`,`Hash Table` | Easy | Biweekly Contest 119 |
2968+
| 2957 | [Remove Adjacent Almost-Equal Characters](/solution/2900-2999/2957.Remove%20Adjacent%20Almost-Equal%20Characters/README_EN.md) | `Greedy`,`String`,`Dynamic Programming` | Medium | Biweekly Contest 119 |
2969+
| 2958 | [Length of Longest Subarray With at Most K Frequency](/solution/2900-2999/2958.Length%20of%20Longest%20Subarray%20With%20at%20Most%20K%20Frequency/README_EN.md) | `Array`,`Hash Table`,`Sliding Window` | Medium | Biweekly Contest 119 |
2970+
| 2959 | [Number of Possible Sets of Closing Branches](/solution/2900-2999/2959.Number%20of%20Possible%20Sets%20of%20Closing%20Branches/README_EN.md) | `Bit Manipulation`,`Graph`,`Enumeration`,`Shortest Path`,`Heap (Priority Queue)` | Hard | Biweekly Contest 119 |
2971+
| 2960 | [Count Tested Devices After Test Operations](/solution/2900-2999/2960.Count%20Tested%20Devices%20After%20Test%20Operations/README_EN.md) | `Array`,`Simulation` | Easy | Weekly Contest 375 |
2972+
| 2961 | [Double Modular Exponentiation](/solution/2900-2999/2961.Double%20Modular%20Exponentiation/README_EN.md) | `Array`,`Math`,`Simulation` | Medium | Weekly Contest 375 |
2973+
| 2962 | [Count Subarrays Where Max Element Appears at Least K Times](/solution/2900-2999/2962.Count%20Subarrays%20Where%20Max%20Element%20Appears%20at%20Least%20K%20Times/README_EN.md) | `Array`,`Sliding Window` | Medium | Weekly Contest 375 |
2974+
| 2963 | [Count the Number of Good Partitions](/solution/2900-2999/2963.Count%20the%20Number%20of%20Good%20Partitions/README_EN.md) | `Array`,`Hash Table`,`Math`,`Combinatorics` | Hard | Weekly Contest 375 |
2975+
| 2964 | [Number of Divisible Triplet Sums](/solution/2900-2999/2964.Number%20of%20Divisible%20Triplet%20Sums/README_EN.md) | | Medium | 🔒 |
29752976

29762977
## Copyright
29772978

solution/summary.md

+1
Original file line numberDiff line numberDiff line change
@@ -3021,3 +3021,4 @@
30213021
- [2961.双模幂运算](/solution/2900-2999/2961.Double%20Modular%20Exponentiation/README.md)
30223022
- [2962.统计最大元素出现至少 K 次的子数组](/solution/2900-2999/2962.Count%20Subarrays%20Where%20Max%20Element%20Appears%20at%20Least%20K%20Times/README.md)
30233023
- [2963.统计好分割方案的数目](/solution/2900-2999/2963.Count%20the%20Number%20of%20Good%20Partitions/README.md)
3024+
- [2964.Number of Divisible Triplet Sums](/solution/2900-2999/2964.Number%20of%20Divisible%20Triplet%20Sums/README.md)

solution/summary_en.md

+1
Original file line numberDiff line numberDiff line change
@@ -3021,3 +3021,4 @@
30213021
- [2961.Double Modular Exponentiation](/solution/2900-2999/2961.Double%20Modular%20Exponentiation/README_EN.md)
30223022
- [2962.Count Subarrays Where Max Element Appears at Least K Times](/solution/2900-2999/2962.Count%20Subarrays%20Where%20Max%20Element%20Appears%20at%20Least%20K%20Times/README_EN.md)
30233023
- [2963.Count the Number of Good Partitions](/solution/2900-2999/2963.Count%20the%20Number%20of%20Good%20Partitions/README_EN.md)
3024+
- [2964.Number of Divisible Triplet Sums](/solution/2900-2999/2964.Number%20of%20Divisible%20Triplet%20Sums/README_EN.md)

0 commit comments

Comments
 (0)