-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathCF672BDifferentIsGood.java
More file actions
41 lines (36 loc) · 943 Bytes
/
CF672BDifferentIsGood.java
File metadata and controls
41 lines (36 loc) · 943 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
33
34
35
36
37
38
39
40
41
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
/**
* See <a href="http://codeforces.com/problemset/problem/672/B">Different is
* Good</a>
*
* @author Brian Yeicol Restrepo Tangarife
*/
public class CF672BDifferentIsGood {
static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) throws IOException {
in.readLine();
String s = in.readLine();
if (s.length() > 26) {
out.print(-1);
} else {
int repetitions = 0;
List<Character> abc = new ArrayList<>();
char[] letters = s.toCharArray();
for (char letter : letters) {
if (abc.contains(letter)) {
repetitions++;
} else {
abc.add(letter);
}
}
out.print(repetitions);
}
out.close();
}
}