We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a4de2c6 commit e79db6eCopy full SHA for e79db6e
Medium/StringReduction.java
@@ -0,0 +1,37 @@
1
+import java.util.*;
2
+import java.io.*;
3
+
4
+class Main {
5
6
+ public static int StringReduction(String str) {
7
+ // code goes here
8
+ int a=0,b=0,c=0;
9
10
+ for (int i =0 ; i<str.length(); i++){
11
+ if (str.charAt(i)=='a') a++;
12
13
+ if (str.charAt(i)=='b') b++;
14
15
+ if (str.charAt(i)=='c') c++;
16
17
+ }
18
19
+ if (a==str.length() || b==str.length() || c==str.length()) return str.length();
20
21
+ if ((a%2==0 && b%2==0 && c%2==0) || (a%2==1 && b%2==1 && c%2==1)){
22
+ return 2;
23
24
+ }else{
25
26
+ return 1;
27
28
29
30
31
+ public static void main (String[] args) {
32
+ // keep this function call here
33
+ Scanner s = new Scanner(System.in);
34
+ System.out.print(StringReduction(s.nextLine()));
35
36
37
+}
0 commit comments