2207. Maximize Number of Subsequences in a String

Обновлено: 2024-03-12
1 мин
[]

Содержание

LeetCode problem 2207

class Solution:
    def maximumSubsequenceCount(self, text: str, pattern: str) -> int:
        res = 0
        cnt = Counter()
        for c in text:
            if c == pattern[1]:
                res += cnt[pattern[0]]
            cnt[c] += 1
        res += max(cnt[pattern[0]], cnt[pattern[1]])
        return res