2559. Count Vowel Strings in Ranges
Prefix Sum,用一个阵列储存每个index符合条件的words数量
再将queries查询条件里对应的index相减
private readonly char[] vowels = new char[]{'a','e','i','o','u'};
public int[] VowelStrings(string[] words, int[][] queries)
{
var checkList = new int[words.Length+1];
var i = 1;
foreach (var word in words)
{
if (vowels.Contains(word[0]) && vowels.Contains(word[word.Length-1]))
{
checkList[i] = checkList[i-1] + 1;
}
else
{
checkList[i] = checkList[i-1];
}
i++;
}
var j = 0;
var result = new int[queries.Length];
foreach (var query in queries)
{
result[j] = checkList[query[1]+1] - checkList[query[0]];
j++;
}
return result;
}