Show problems as
Classic problem #3120EasyHash TableString

Count the Number of Special Characters I

Real-world version: Letters Stamped Both Ways
Tracked in this browser only
Read Count the Number of Special Characters I on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

A plate reads word, a mix of lowercase and uppercase English letters.

A letter of the alphabet is stamped both ways when the plate holds it in lowercase somewhere and in uppercase somewhere. Return how many letters of the alphabet are stamped both ways.

Examples

Example 1

Input
word = "kEttLeKnObs"
Output
2

The letter k appears as both k and K, and the letter e appears as both e and E. The letters l, o, t, n, b and s appear in only one case each.

Example 2

Input
word = "mMnNoOpPqQ"
Output
5

All five letters turn up in both cases.

Example 3

Input
word = "abcdefghij"
Output
0

Nothing on the plate is uppercase, so no letter is stamped both ways.

Constraints

  • 1 <= word.length <= 50
  • word consists of lowercase and uppercase English letters only

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def number_of_special_chars(word: str) -> int:
Java
public int numberOfSpecialChars(String word)