mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-14 09:59:41 +01:00
20 lines
506 B
C#
20 lines
506 B
C#
|
public class Solution {
|
||
|
private static int GetMask(string allowed) {
|
||
|
var mask = 0;
|
||
|
|
||
|
foreach (var c in allowed) {
|
||
|
mask |= 1 << (c - 'a');
|
||
|
}
|
||
|
|
||
|
return mask;
|
||
|
}
|
||
|
|
||
|
private static bool IsConsistent(int mask, string word)
|
||
|
=> word.All(c => (mask & (1 << (c - 'a'))) != 0);
|
||
|
|
||
|
public int CountConsistentStrings(string allowed, string[] words) {
|
||
|
var mask = GetMask(allowed);
|
||
|
return words.Count(word => IsConsistent(mask, word));
|
||
|
}
|
||
|
}
|