Skip to content

Commit baa66bc

Browse files
solves consecutive chacters
1 parent ee0832d commit baa66bc

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@
367367
| 1436 | [Destination City](https://leetcode.com/problems/destination-city) | [![Java](assets/java.png)](src/DestinationCity.java) | |
368368
| 1437 | [Check If All 1's Are at Least Length K Places Away](https://leetcode.com/problems/check-if-all-1s-are-at-least-length-k-places-away) | [![Java](assets/java.png)](src/CheckIfAll1sAreAtLeastKPlacesAway.java) | |
369369
| 1441 | [Build An Array With Stack Operation](https://leetcode.com/problems/build-an-array-with-stack-operations) | [![Java](assets/java.png)](src/BuildAnArrayWithStackOperations.java) | |
370-
| 1446 | [Consecutive Characters](https://leetcode.com/problems/consecutive-characters) | | |
370+
| 1446 | [Consecutive Characters](https://leetcode.com/problems/consecutive-characters) | [![Java](assets/java.png)](src/ConsecutiveCharacters.java) | |
371371
| 1450 | [Number of Students Doing Homework at Given Time](https://leetcode.com/problems/number-of-students-doing-homework-at-a-given-time) | | |
372372
| 1455 | [Check If Word Occurs as Prefix of any Word in Sentence](https://leetcode.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence) | | |
373373
| 1460 | [Make 2 Arrays Equal by Reversing Sub Arrays](https://leetcode.com/problems/make-two-arrays-equal-by-reversing-sub-arrays) | | |

src/ConsecutiveCharacters.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
public class ConsecutiveCharacters {
2+
public int maxPower(String s) {
3+
int power = 1;
4+
char current = s.charAt(0);
5+
for (int index = 1, frequency = 1 ; index < s.length() ; index++) {
6+
if (s.charAt(index) == current) frequency++;
7+
else {
8+
current = s.charAt(index);
9+
frequency = 1;
10+
}
11+
power = Math.max(power, frequency);
12+
}
13+
return power;
14+
}
15+
}

0 commit comments

Comments
 (0)