File tree Expand file tree Collapse file tree 2 files changed +37
-1
lines changed
Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change 1- # 1,524 LeetCode solutions in JavaScript
1+ # 1,525 LeetCode solutions in JavaScript
22
33[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
44
135413541754|[ Largest Merge Of Two Strings] ( ./solutions/1754-largest-merge-of-two-strings.js ) |Medium|
135513551755|[ Closest Subsequence Sum] ( ./solutions/1755-closest-subsequence-sum.js ) |Hard|
135613561758|[ Minimum Changes To Make Alternating Binary String] ( ./solutions/1758-minimum-changes-to-make-alternating-binary-string.js ) |Easy|
1357+ 1759|[ Count Number of Homogenous Substrings] ( ./solutions/1759-count-number-of-homogenous-substrings.js ) |Medium|
135713581764|[ Form Array by Concatenating Subarrays of Another Array] ( ./solutions/1764-form-array-by-concatenating-subarrays-of-another-array.js ) |Medium|
135813591765|[ Map of Highest Peak] ( ./solutions/1765-map-of-highest-peak.js ) |Medium|
135913601768|[ Merge Strings Alternately] ( ./solutions/1768-merge-strings-alternately.js ) |Easy|
Original file line number Diff line number Diff line change 1+ /**
2+ * 1759. Count Number of Homogenous Substrings
3+ * https://leetcode.com/problems/count-number-of-homogenous-substrings/
4+ * Difficulty: Medium
5+ *
6+ * Given a string s, return the number of homogenous substrings of s. Since the answer may be
7+ * too large, return it modulo 109 + 7.
8+ *
9+ * A string is homogenous if all the characters of the string are the same.
10+ *
11+ * A substring is a contiguous sequence of characters within a string.
12+ */
13+
14+ /**
15+ * @param {string } s
16+ * @return {number }
17+ */
18+ var countHomogenous = function ( s ) {
19+ const mod = 1e9 + 7 ;
20+ let result = 0 ;
21+ let streak = 1 ;
22+
23+ for ( let i = 1 ; i < s . length ; i ++ ) {
24+ if ( s [ i ] === s [ i - 1 ] ) {
25+ streak ++ ;
26+ } else {
27+ result = ( result + ( streak * ( streak + 1 ) / 2 ) ) % mod ;
28+ streak = 1 ;
29+ }
30+ }
31+
32+ result = ( result + ( streak * ( streak + 1 ) / 2 ) ) % mod ;
33+
34+ return result ;
35+ } ;
You can’t perform that action at this time.
0 commit comments