Skip to content
LC-3120 Easy LeetCode

3120. Count the Number of Special Characters I

Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 65% Topics: Hash Table, String
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(n + 26)
# Space: O(26)

import itertools


# hash table
class Solution(object):
    def numberOfSpecialChars(self, word):
        """
        :type word: str
        :rtype: int
        """
        lookup1 = [False]*26
        lookup2 = [False]*26
        for x in word:
            if x.islower():
                lookup1[ord(x)-ord('a')] = True
            else:
                lookup2[ord(x)-ord('A')] = True
        return sum(x == y == True for x, y in itertools.izip(lookup1, lookup2))

Solution from kamyu104/LeetCode-Solutions · MIT