LeetCode solutions

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

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 3ms, memory 17.1MB, accepted 2025-12-29.

python
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

Source