Skip to content

Commit

Permalink
Create count-the-number-of-special-characters-i.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
kamyu104 authored Apr 21, 2024
1 parent 64ea4bf commit 70358e2
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions C++/count-the-number-of-special-characters-i.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Time: O(n + 26)
// Space: O(26)

// hash table
class Solution {
public:
int numberOfSpecialChars(string word) {
vector<bool> lookup1(26);
vector<bool> lookup2(26);
for (const auto& x : word) {
if (islower(x)) {
lookup1[x - 'a'] = true;
} else {
lookup2[x - 'A'] = true;
}
}
int result = 0;
for (int i = 0; i < 26; ++i) {
if (lookup1[i] == lookup2[i] && lookup2[i] == true) {
++result;
}
}
return result;
}
};

0 comments on commit 70358e2

Please sign in to comment.