forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_1180.java
More file actions
26 lines (24 loc) · 727 Bytes
/
_1180.java
File metadata and controls
26 lines (24 loc) · 727 Bytes
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
package com.fishercoder.solutions;
public class _1180 {
public static class Solution1 {
public int countLetters(String S) {
int count = 0;
for (int i = 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();
}
return count;
}
private int countTimes(String str) {
int len = str.length();
int times = 0;
while (len > 0) {
times += len--;
}
return times;
}
}
}