Skip to content

Add LetCode 1684 cpp, java, cs #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<string>& words) {
int markedAllowed = markCharacters(allowed);
int answer = 0;

for (string word : words) {
int markedWord = markCharacters(word);

if ((markedWord & markedAllowed) == markedWord)
answer++;
}

return answer;
}
};
26 changes: 26 additions & 0 deletions Algorithms/Easy/1684_CountTheNumberOfConsistentStrings/Solution.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}