Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ccddc41

Browse files
committed
Add solution #3084
1 parent 268db1b commit ccddc41

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2162,6 +2162,7 @@
21622162
3076|[Shortest Uncommon Substring in an Array](./solutions/3076-shortest-uncommon-substring-in-an-array.js)|Medium|
21632163
3079|[Find the Sum of Encrypted Integers](./solutions/3079-find-the-sum-of-encrypted-integers.js)|Easy|
21642164
3083|[Existence of a Substring in a String and Its Reverse](./solutions/3083-existence-of-a-substring-in-a-string-and-its-reverse.js)|Easy|
2165+
3084|[Count Substrings Starting and Ending with Given Character](./solutions/3084-count-substrings-starting-and-ending-with-given-character.js)|Medium|
21652166
3105|[Longest Strictly Increasing or Strictly Decreasing Subarray](./solutions/3105-longest-strictly-increasing-or-strictly-decreasing-subarray.js)|Easy|
21662167
3108|[Minimum Cost Walk in Weighted Graph](./solutions/3108-minimum-cost-walk-in-weighted-graph.js)|Hard|
21672168
3110|[Score of a String](./solutions/3110-score-of-a-string.js)|Easy|
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* 3084. Count Substrings Starting and Ending with Given Character
3+
* https://leetcode.com/problems/count-substrings-starting-and-ending-with-given-character/
4+
* Difficulty: Medium
5+
*
6+
* You are given a string s and a character c. Return the total number of substrings of s
7+
* that start and end with c.
8+
*/
9+
10+
/**
11+
* @param {string} s
12+
* @param {character} c
13+
* @return {number}
14+
*/
15+
var countSubstrings = function(s, c) {
16+
let count = 0;
17+
for (const char of s) {
18+
if (char === c) count++;
19+
}
20+
return (count * (count + 1)) / 2;
21+
};

0 commit comments

Comments
 (0)