Description
You are given a string word
. A letter is called special if it appears both in lowercase and uppercase in word
.
Return the number of special letters in word
.
Example 1:
Input: word = "aaAbcBC"
Output: 3
Explanation:
The special characters in word
are 'a'
, 'b'
, and 'c'
.
Example 2:
Input: word = "abc"
Output: 0
Explanation:
No character in word
appears in uppercase.
Example 3:
Input: word = "abBCab"
Output: 1
Explanation:
The only special character in word
is 'b'
.
Constraints:
1 <= word.length <= 50
word
consists of only lowercase and uppercase English letters.
Solution
Python3
class Solution:
def numberOfSpecialChars(self, word: str) -> int:
A = [[False, False] for _ in range(26)]
for x in word:
if x.isupper():
A[ord(x) - ord('A')][1] = True
else:
A[ord(x) - ord('a')][0] = True
res = 0
for i in range(26):
if A[i][0] and A[i][1]:
res += 1
return res