Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ebabeb1

Browse files
Create Check if Any Element Has Prime Frequency.java
1 parent a802621 commit ebabeb1

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution {
2+
public boolean checkPrimeFrequency(int[] nums) {
3+
Map<Integer, Integer> map = new HashMap<>();
4+
for (int num : nums) {
5+
map.put(num, map.getOrDefault(num, 0) + 1);
6+
}
7+
for (Integer value : map.values()) {
8+
if (isPrime(value)) {
9+
return true;
10+
}
11+
}
12+
return false;
13+
}
14+
15+
private static boolean isPrime(int num) {
16+
for (int i = 2; i <= num / 2; i++) {
17+
if (num % i == 0) {
18+
return false;
19+
}
20+
}
21+
return num > 1 && true;
22+
}
23+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /