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 1b85673
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 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,23 @@
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
print(d)
return sum(v == 0 for v in d.values())


print(Solution().numberOfSpecialChars("aaAbcBC"))

0 comments on commit 1b85673

Please sign in to comment.