3408. Count the Number of Special Characters I
My accepted Python solution to LeetCode problem 3408, Count the Number of Special Characters I, running in 3ms.
- Difficulty: Easy
- Python
- Runtime 3ms
- Memory 17.1MB
- 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 3ms, memory 17.1MB, accepted 2025-12-29.
class Solution:
def numberOfSpecialChars(self, word: str) -> int:
lower = set(c for c in word if c.islower())
upper = set(c for c in word if c.isupper())
count = 0
for c in lower:
if c.upper() in upper:
count += 1
return count