Skip to content

Commit b8a29e6

Browse files
authored
Create Substrings That Begin and End With the Same Letter.java
1 parent 4b1a03b commit b8a29e6

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public long numberOfSubstrings(String s) {
3+
int n = s.length();
4+
long result = 0;
5+
long[] prefixCount = new long[26];
6+
for (int i = 0; i < n; i++) {
7+
prefixCount[s.charAt(i) - 'a']++;
8+
result += prefixCount[s.charAt(i) - 'a'];
9+
}
10+
return result;
11+
}
12+
}

0 commit comments

Comments
 (0)