Skip to content

Commit 59c3372

Browse files
add 3591
1 parent 5395a86 commit 59c3372

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

  • paginated_contents/algorithms/4th_thousand
  • src/main/java/com/fishercoder/solutions/fourththousand

‎paginated_contents/algorithms/4th_thousand/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
| 3622 | [Check Divisibility by Digit Sum and Product](https://leetcode.com/problems/check-divisibility-by-digit-sum-and-product/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3622.java) | | Easy |
7777
| 3608 | [Minimum Time for K Connected Components](https://leetcode.com/problems/minimum-time-for-k-connected-components/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3608.java) | | Medium | UnionFind
7878
| 3606 | [Coupon Code Validator](https://leetcode.com/problems/coupon-code-validator/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3606.java) | | Easy |
79+
| 3591 | [Check if Any Element Has Prime Frequency](https://leetcode.com/problems/check-if-any-element-has-prime-frequency/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3591.java) | | Easy |
7980
| 3582 | [Generate Tag for Video Caption](https://leetcode.com/problems/generate-tag-for-video-caption/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3582.java) | | Easy |
8081
| 3581 | [Count Odd Letters from Number](https://leetcode.com/problems/count-odd-letters-from-number/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3581.java) | | Easy |
8182
| 3571 | [Find the Shortest Superstring II](https://leetcode.com/problems/find-the-shortest-superstring-ii/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3571.java) | | Easy |
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.fishercoder.solutions.fourththousand;
2+
3+
import java.util.Arrays;
4+
import java.util.HashMap;
5+
import java.util.Map;
6+
7+
public class _3591 {
8+
public static class Solution1 {
9+
public boolean checkPrimeFrequency(int[] nums) {
10+
Map<Integer, Integer> map = new HashMap<>();
11+
for (int num : nums) {
12+
map.put(num, map.getOrDefault(num, 0) + 1);
13+
}
14+
for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
15+
if (isPrime(entry.getValue())) {
16+
return true;
17+
}
18+
}
19+
return false;
20+
}
21+
22+
private boolean isPrime(Integer n) {
23+
if (n <= 2) {
24+
return false;
25+
}
26+
boolean[] isPrime = new boolean[n + 1];
27+
Arrays.fill(isPrime, true);
28+
isPrime[0] = false;
29+
isPrime[1] = false;
30+
for (int i = 2; i < n; i++) {
31+
if (isPrime[i]) {
32+
for (int j = 2; i * j <= n; j++) {
33+
isPrime[i * j] = false;
34+
}
35+
}
36+
}
37+
return isPrime[n];
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)