Skip to content

Commit

Permalink
leetcode count # of special characters
Browse files Browse the repository at this point in the history
  • Loading branch information
ferhatelmas committed Apr 22, 2024
1 parent a494f1c commit 97f09a8
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions leetcode/algorithms/easy/count_the_number_of_special_characters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution:
def numberOfSpecialChars(self, word: str) -> int:
s, d = set(), {}
for e in word:
if e in s:
continue
s.add(e)
v = e.lower()
if v in d:
if v == e:
d[v] -= 1
else:
d[v] += 1
else:
if v == e:
d[v] = -1
else:
d[v] = 1
return sum(v == 0 for v in d.values())

0 comments on commit 97f09a8

Please sign in to comment.