diff --git a/Algorithms/Easy/1684_CountTheNumberOfConsistentStrings/Solution.cpp b/Algorithms/Easy/1684_CountTheNumberOfConsistentStrings/Solution.cpp new file mode 100644 index 0000000..27c7000 --- /dev/null +++ b/Algorithms/Easy/1684_CountTheNumberOfConsistentStrings/Solution.cpp @@ -0,0 +1,27 @@ +class Solution { +public: + int markCharacters(string &word) { + int marked = 0; + + for (char ch : word) { + int position = ch - 'a'; + marked |= 1 << position; + } + + return marked; + } + + int countConsistentStrings(string allowed, vector& words) { + int markedAllowed = markCharacters(allowed); + int answer = 0; + + for (string word : words) { + int markedWord = markCharacters(word); + + if ((markedWord & markedAllowed) == markedWord) + answer++; + } + + return answer; + } +}; \ No newline at end of file diff --git a/Algorithms/Easy/1684_CountTheNumberOfConsistentStrings/Solution.cs b/Algorithms/Easy/1684_CountTheNumberOfConsistentStrings/Solution.cs new file mode 100644 index 0000000..664303c --- /dev/null +++ b/Algorithms/Easy/1684_CountTheNumberOfConsistentStrings/Solution.cs @@ -0,0 +1,26 @@ +public class Solution { + public int MarkCharacters(String word) { + int marked = 0; + + foreach (char ch in word.ToCharArray()) { + int position = ch - 'a'; + marked |= 1 << position; + } + + return marked; + } + + public int CountConsistentStrings(string allowed, string[] words) { + int markedAllowed = MarkCharacters(allowed); + int answer = 0; + + foreach (String word in words) { + int markedWord = MarkCharacters(word); + + if ((markedWord & markedAllowed) == markedWord) + answer++; + } + + return answer; + } +} \ No newline at end of file diff --git a/Algorithms/Easy/1684_CountTheNumberOfConsistentStrings/Solution.java b/Algorithms/Easy/1684_CountTheNumberOfConsistentStrings/Solution.java new file mode 100644 index 0000000..753b3ee --- /dev/null +++ b/Algorithms/Easy/1684_CountTheNumberOfConsistentStrings/Solution.java @@ -0,0 +1,26 @@ +class Solution { + public int markCharacters(String word) { + int marked = 0; + + for (char ch : word.toCharArray()) { + int position = Character.getNumericValue(ch); + marked |= 1 << position; + } + + return marked; + } + + public int countConsistentStrings(String allowed, String[] words) { + int markedAllowed = markCharacters(allowed); + int answer = 0; + + for (String word : words) { + int markedWord = markCharacters(word); + + if ((markedWord & markedAllowed) == markedWord) + answer++; + } + + return answer; + } +} \ No newline at end of file