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

Appearance settings

Commit e79db6e

Browse filesBrowse files
authored
Create StringReduction.java
1 parent a4de2c6 commit e79db6e
Copy full SHA for e79db6e

File tree

Expand file treeCollapse file tree

1 file changed

+37
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+37
-0
lines changed

‎Medium/StringReduction.java

Copy file name to clipboard
+37Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.