| | 1 | | // -------------------------------------------------------------------------------- |
| | 2 | | // Copyright (C) 2025 Eugene Eremeev (also known as Yevhenii Yeriemeieiv). |
| | 3 | | // All Rights Reserved. |
| | 4 | | // -------------------------------------------------------------------------------- |
| | 5 | | // This software is the confidential and proprietary information of Eugene Eremeev |
| | 6 | | // (also known as Yevhenii Yeriemeieiv) ("Confidential Information"). You shall not |
| | 7 | | // disclose such Confidential Information and shall use it only in accordance with |
| | 8 | | // the terms of the license agreement you entered into with Eugene Eremeev (also |
| | 9 | | // known as Yevhenii Yeriemeieiv). |
| | 10 | | // -------------------------------------------------------------------------------- |
| | 11 | |
|
| | 12 | | namespace LeetCode.Algorithms.CountVowelStringsInRanges; |
| | 13 | |
|
| | 14 | | /// <inheritdoc /> |
| | 15 | | public class CountVowelStringsInRangesPrefixSum : ICountVowelStringsInRanges |
| | 16 | | { |
| 2 | 17 | | private readonly HashSet<char> _vowelsHashSet = |
| 2 | 18 | | [ |
| 2 | 19 | | 'a', |
| 2 | 20 | | 'e', |
| 2 | 21 | | 'i', |
| 2 | 22 | | 'o', |
| 2 | 23 | | 'u' |
| 2 | 24 | | ]; |
| | 25 | |
|
| | 26 | | public int[] VowelStrings(string[] words, int[][] queries) |
| 2 | 27 | | { |
| 2 | 28 | | var prefixSum = new int[words.Length + 1]; |
| | 29 | |
|
| 20 | 30 | | for (var i = 0; i < words.Length; i++) |
| 8 | 31 | | { |
| 8 | 32 | | if (_vowelsHashSet.Contains(words[i][0]) && _vowelsHashSet.Contains(words[i][^1])) |
| 7 | 33 | | { |
| 7 | 34 | | prefixSum[i + 1] = prefixSum[i] + 1; |
| 7 | 35 | | } |
| | 36 | | else |
| 1 | 37 | | { |
| 1 | 38 | | prefixSum[i + 1] = prefixSum[i]; |
| 1 | 39 | | } |
| 8 | 40 | | } |
| | 41 | |
|
| 2 | 42 | | var result = new int[queries.Length]; |
| | 43 | |
|
| 16 | 44 | | for (var i = 0; i < queries.Length; i++) |
| 6 | 45 | | { |
| 6 | 46 | | result[i] = prefixSum[queries[i][1] + 1] - prefixSum[queries[i][0]]; |
| 6 | 47 | | } |
| | 48 | |
|
| 2 | 49 | | return result; |
| 2 | 50 | | } |
| | 51 | | } |