LeetCode solutions

2401. Count Asterisks

My accepted Python solution to LeetCode problem 2401, Count Asterisks, running in 4ms.

  • Difficulty: Easy
  • Python
  • Runtime 4ms
  • Memory 17.3MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 4ms, memory 17.3MB, accepted 2025-12-29.

python
class Solution:
    def countAsterisks(self, s: str) -> int:
        count = 0
        in_pair = False
        for c in s:
            if c == '|':
                in_pair = not in_pair
            elif c == '*' and not in_pair:
                count += 1
        return count

Source