Maximize Number of Subsequences in a String LeetCode solution in Python

1
class Solution:
2
def maximumSubsequenceCount(self, text: str, pattern: str) -> int:
3
total = count_a = count_b = 0
4
for c in text:
5
if c == pattern[1]:
6
total += count_a
7
count_b += 1
8
if c == pattern[0]:
9
count_a += 1
10

11
return total + max(count_a, count_b)

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0