We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d4f6b3d commit 4b80626Copy full SHA for 4b80626
1 file changed
ConsecutiveCharacters.java
@@ -0,0 +1,35 @@
1
+# Given a string s, the power of the string is the maximum length of a non-empty substring that contains only one unique character.
2
+# Return the power of the string.
3
+
4
+import java.util.Scanner;
5
6
+public class ConsecutiveCharacters{
7
+ public static void main(String[] args){
8
+ Scanner sc=new Scanner(System.in);
9
+ String str = sc.nextLine();
10
+ int result = maxPower(str);
11
+ System.out.println(result);
12
+ }
13
+ public static int maxPower(String s) {
14
+ if(s.length()==1){
15
+ return 1;
16
17
+ int count=1;
18
+ int max=0;
19
+ char ch = s.charAt(0);
20
21
+ for(int i=1;i<s.length();i++){
22
+ char test=s.charAt(i);
23
+ if(test==ch){
24
+ count++;
25
+ }else{
26
+ ch=test;
27
+ count=1;
28
29
+ if(max<count){
30
+ max=count;
31
32
33
+ return max;
34
35
+}
0 commit comments