-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClassCaptain.java
More file actions
32 lines (26 loc) · 845 Bytes
/
ClassCaptain.java
File metadata and controls
32 lines (26 loc) · 845 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package HashMap;
import java.util.HashMap;
import java.util.Scanner;
public class ClassCaptain {
public static Character solution1(int len, String inputString) {
Character result = null;
int maxVoteCount = 0;
HashMap<Character, Integer> voteInfo = new HashMap<>();
for (char c : inputString.toCharArray()) {
voteInfo.put(c, voteInfo.getOrDefault(c,0) + 1);
}
for (char c: voteInfo.keySet()) {
if (maxVoteCount < voteInfo.get(c)) {
maxVoteCount = voteInfo.get(c);
result = c;
}
}
return result;
}
public void main() {
Scanner in=new Scanner(System.in);
int len = in.nextInt();
String inputString = in.next();
System.out.print(solution1(len, inputString));
}
}