Skip to content

Commit bd4b0de

Browse files
authored
feat: add solution to lc problem: No.2248 (doocs#805)
No.2248.Intersection of Multiple Arrays
1 parent c800761 commit bd4b0de

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

solution/2200-2299/2248.Intersection of Multiple Arrays/README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,23 @@ nums[0] = [<em><strong>3</strong></em>,1,2,<em><strong>4</strong></em>,5],nums
5757
<!-- 这里可写当前语言的特殊实现逻辑 -->
5858

5959
```java
60-
60+
class Solution {
61+
public List<Integer> intersection(int[][] nums) {
62+
int[] cnt = new int[1001];
63+
for (int[] num : nums) {
64+
for (int i : num) {
65+
cnt[i]++;
66+
}
67+
}
68+
List<Integer> ans = new ArrayList<>();
69+
for (int i = 1; i <= 1000; i++) {
70+
if (cnt[i] == nums.length) {
71+
ans.add(i);
72+
}
73+
}
74+
return ans;
75+
}
76+
}
6177
```
6278

6379
### **TypeScript**

solution/2200-2299/2248.Intersection of Multiple Arrays/README_EN.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,23 @@ There does not exist any integer present both in nums[0] and nums[1], so we retu
4747
### **Java**
4848

4949
```java
50-
50+
class Solution {
51+
public List<Integer> intersection(int[][] nums) {
52+
int[] cnt = new int[1001];
53+
for (int[] num : nums) {
54+
for (int i : num) {
55+
cnt[i]++;
56+
}
57+
}
58+
List<Integer> ans = new ArrayList<>();
59+
for (int i = 1; i <= 1000; i++) {
60+
if (cnt[i] == nums.length) {
61+
ans.add(i);
62+
}
63+
}
64+
return ans;
65+
}
66+
}
5167
```
5268

5369
### **TypeScript**
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public List<Integer> intersection(int[][] nums) {
3+
int[] cnt = new int[1001];
4+
for (int[] num : nums) {
5+
for (int i : num) {
6+
cnt[i]++;
7+
}
8+
}
9+
List<Integer> ans = new ArrayList<>();
10+
for (int i = 1; i <= 1000; i++) {
11+
if (cnt[i] == nums.length) {
12+
ans.add(i);
13+
}
14+
}
15+
return ans;
16+
}
17+
}

0 commit comments

Comments
 (0)