File tree 2 files changed +33
-0
lines changed
2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * 1358. Number of Substrings Containing All Three Characters
3
+ * https://leetcode.com/problems/number-of-substrings-containing-all-three-characters/
4
+ * Difficulty: Medium
5
+ *
6
+ * Given a string s consisting only of characters a, b and c.
7
+ *
8
+ * Return the number of substrings containing at least one occurrence of all these
9
+ * characters a, b and c.
10
+ */
11
+
12
+ /**
13
+ * @param {string } s
14
+ * @return {number }
15
+ */
16
+ var numberOfSubstrings = function ( s ) {
17
+ const count = [ 0 , 0 , 0 ] ;
18
+ let result = 0 ;
19
+ let left = 0 ;
20
+
21
+ for ( let right = 0 ; right < s . length ; right ++ ) {
22
+ count [ s [ right ] . charCodeAt ( 0 ) - 97 ] ++ ;
23
+
24
+ while ( count [ 0 ] > 0 && count [ 1 ] > 0 && count [ 2 ] > 0 ) {
25
+ result += s . length - right ;
26
+ count [ s [ left ] . charCodeAt ( 0 ) - 97 ] -- ;
27
+ left ++ ;
28
+ }
29
+ }
30
+
31
+ return result ;
32
+ } ;
Original file line number Diff line number Diff line change 653
653
1351|[ Count Negative Numbers in a Sorted Matrix] ( ./1351-count-negative-numbers-in-a-sorted-matrix.js ) |Easy|
654
654
1352|[ Product of the Last K Numbers] ( ./1352-product-of-the-last-k-numbers.js ) |Medium|
655
655
1356|[ Sort Integers by The Number of 1 Bits] ( ./1356-sort-integers-by-the-number-of-1-bits.js ) |Easy|
656
+ 1358|[ Number of Substrings Containing All Three Characters] ( ./1358-number-of-substrings-containing-all-three-characters.js ) |Medium|
656
657
1360|[ Number of Days Between Two Dates] ( ./1360-number-of-days-between-two-dates.js ) |Easy|
657
658
1365|[ How Many Numbers Are Smaller Than the Current Number] ( ./1365-how-many-numbers-are-smaller-than-the-current-number.js ) |Easy|
658
659
1366|[ Rank Teams by Votes] ( ./1366-rank-teams-by-votes.js ) |Medium|
You can’t perform that action at this time.
0 commit comments