- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_1180.java
26 lines (24 loc) · 742 Bytes
/
_1180.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
packagecom.fishercoder.solutions.secondthousand;
publicclass_1180 {
publicstaticclassSolution1 {
publicintcountLetters(StringS) {
intcount = 0;
for (inti = 0, j = 1; j < S.length() && i <= j; ) {
while (j < S.length() && S.charAt(i) == S.charAt(j)) {
j++;
}
count += countTimes(S.substring(i, j));
i += S.substring(i, j).length();
}
returncount;
}
privateintcountTimes(Stringstr) {
intlen = str.length();
inttimes = 0;
while (len > 0) {
times += len--;
}
returntimes;
}
}
}