本文主要是介绍leetcode_2586 统计范围元音字符串,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1. 题意
元音字符串是首尾都是元音字母的字符串。
给字符数组,让你找出指定范围内的元音字符串的个数。
统计范围元音字符串
2. 题解
直接模拟即可
class Solution {
public:int vowelStrings(vector<string>& words, int left, int right) {unordered_set<int> us{'a','e','i','o','u'};int ans = 0;int sz = words.size();for ( int i = 0; i < sz; ++i) {if ( i >= left && i <= right) {int len = words[i].size();if (us.count(words[i][0]) && us.count(words[i][len - 1]))++ans;}}return ans;}
};
这篇关于leetcode_2586 统计范围元音字符串的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!