2401. Count Asterisks
My accepted Python solution to LeetCode problem 2401, Count Asterisks, running in 4ms.
- Difficulty: Easy
- Python
- Runtime 4ms
- Memory 17.3MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 4ms, memory 17.3MB, accepted 2025-12-29.
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