All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : March 11, 2025
Last updated : March 11, 2025
Related Topics : Hash Table, String, Sliding Window
Acceptance Rate : 73.01 %
class Solution:
def numberOfSubstrings(self, s: str) -> int:
abc = [-1, -1, -1]
output = 0
for i, x in enumerate(s) :
abc[ord(x) - ord('a')] = i
if -1 not in abc :
output += 1 + min(abc)
return output
class Solution:
def numberOfSubstrings(self, s: str) -> int:
a = b = c = -1
output = 0
for i, x in enumerate(s) :
match x :
case 'a' :
a = i
case 'b' :
b = i
case 'c' :
c = i
if min(a, b, c) != -1 :
output += 1 + min(a, b, c)
return output