Skip to content

Commit 90c5651

Browse files
authored
Create 3084-count-substrings-starting-and-ending-with-given-character.js
1 parent 21c881a commit 90c5651

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @param {string} s
3+
* @param {character} c
4+
* @return {number}
5+
*/
6+
const countSubstrings = function(s, c) {
7+
const n = s.length
8+
const arr = []
9+
for(let i = 0; i < n; i++) {
10+
if(s[i] === c) {
11+
arr.push(i)
12+
}
13+
}
14+
let len = arr.length
15+
let res = 0
16+
while(len) {
17+
res += len
18+
len--
19+
}
20+
21+
return res
22+
};

0 commit comments

Comments
 (0)