- Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathStringReduction.java
37 lines (24 loc) · 708 Bytes
/
StringReduction.java
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
importjava.util.*;
importjava.io.*;
classMain {
publicstaticintStringReduction(Stringstr) {
// code goes here
inta=0,b=0,c=0;
for (inti =0 ; i<str.length(); i++){
if (str.charAt(i)=='a') a++;
if (str.charAt(i)=='b') b++;
if (str.charAt(i)=='c') c++;
}
if (a==str.length() || b==str.length() || c==str.length()) returnstr.length();
if ((a%2==0 && b%2==0 && c%2==0) || (a%2==1 && b%2==1 && c%2==1)){
return2;
}else{
return1;
}
}
publicstaticvoidmain (String[] args) {
// keep this function call here
Scanners = newScanner(System.in);
System.out.print(StringReduction(s.nextLine()));
}
}