{"id":9977,"date":"2023-03-11T20:32:34","date_gmt":"2023-03-12T04:32:34","guid":{"rendered":"https:\/\/zxi.mytechroad.com\/blog\/?p=9977"},"modified":"2023-03-11T20:35:40","modified_gmt":"2023-03-12T04:35:40","slug":"leetcode-2586-count-the-number-of-vowel-strings-in-range","status":"publish","type":"post","link":"https:\/\/zxi.mytechroad.com\/blog\/string\/leetcode-2586-count-the-number-of-vowel-strings-in-range\/","title":{"rendered":"\u82b1\u82b1\u9171 LeetCode 2586. Count the Number of Vowel Strings in Range"},"content":{"rendered":"\n<p>You are given a&nbsp;<strong>0-indexed<\/strong>&nbsp;array of string&nbsp;<code>words<\/code>&nbsp;and two integers&nbsp;<code>left<\/code>&nbsp;and&nbsp;<code>right<\/code>.<\/p>\n\n\n\n<p>A string is called a&nbsp;<strong>vowel string<\/strong>&nbsp;if it starts with a vowel character and ends with a vowel character where vowel characters are&nbsp;<code>'a'<\/code>,&nbsp;<code>'e'<\/code>,&nbsp;<code>'i'<\/code>,&nbsp;<code>'o'<\/code>, and&nbsp;<code>'u'<\/code>.<\/p>\n\n\n\n<p>Return&nbsp;<em>the number of vowel strings&nbsp;<\/em><code>words[i]<\/code><em>&nbsp;where&nbsp;<\/em><code>i<\/code><em>&nbsp;belongs to the inclusive range&nbsp;<\/em><code>[left, right]<\/code>.<\/p>\n\n\n\n<p><strong>Example 1:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted;crayon:false\"><strong>Input:<\/strong> words = [\"are\",\"amy\",\"u\"], left = 0, right = 2\n<strong>Output:<\/strong> 2\n<strong>Explanation:<\/strong> \n- \"are\" is a vowel string because it starts with 'a' and ends with 'e'.\n- \"amy\" is not a vowel string because it does not end with a vowel.\n- \"u\" is a vowel string because it starts with 'u' and ends with 'u'.\nThe number of vowel strings in the mentioned range is 2.\n<\/pre>\n\n\n\n<p><strong>Example 2:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted;crayon:false\"><strong>Input:<\/strong> words = [\"hey\",\"aeo\",\"mu\",\"ooo\",\"artro\"], left = 1, right = 4\n<strong>Output:<\/strong> 3\n<strong>Explanation:<\/strong> \n- \"aeo\" is a vowel string because it starts with 'a' and ends with 'o'.\n- \"mu\" is not a vowel string because it does not start with a vowel.\n- \"ooo\" is a vowel string because it starts with 'o' and ends with 'o'.\n- \"artro\" is a vowel string because it starts with 'a' and ends with 'o'.\nThe number of vowel strings in the mentioned range is 3.\n<\/pre>\n\n\n\n<p><strong>Constraints:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>1 &lt;= words.length &lt;= 1000<\/code><\/li><li><code>1 &lt;= words[i].length &lt;= 10<\/code><\/li><li><code>words[i]<\/code>&nbsp;consists of only lowercase English letters.<\/li><li><code>0 &lt;= left &lt;= right &lt; words.length<\/code><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Solution:<\/strong><\/h2>\n\n\n\n<p>Iterator overs words, from left to right. Check the first and last element of the string.<\/p>\n\n\n\n<p>Time complexity: O(|right &#8211; left + 1|)<br>Space complexity: O(1)<\/p>\n\n\n\n<div class=\"responsive-tabs\">\n<h2 class=\"tabtitle\">C++<\/h2>\n<div class=\"tabcontent\">\n\n<pre lang=\"c++\">\n\/\/ Author: Huahua\nclass Solution {\npublic:\n  int vowelStrings(vector<string>& words, int left, int right) {\n    auto isVowel = [](char c) {\n      return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';\n    };\n    return count_if(begin(words) + left, begin(words) + right + 1, [&](const string& w) {\n      return isVowel(w.front()) && isVowel(w.back());\n    });\n  }\n};\n<\/pre>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>You are given a&nbsp;0-indexed&nbsp;array of string&nbsp;words&nbsp;and two integers&nbsp;left&nbsp;and&nbsp;right. A string is called a&nbsp;vowel string&nbsp;if it starts with a vowel character and ends with a vowel&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[47],"tags":[222,4,449],"class_list":["post-9977","post","type-post","status-publish","format-standard","hentry","category-string","tag-easy","tag-string","tag-vowel","entry","simple"],"_links":{"self":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/9977","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/comments?post=9977"}],"version-history":[{"count":3,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/9977\/revisions"}],"predecessor-version":[{"id":9980,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/9977\/revisions\/9980"}],"wp:attachment":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/media?parent=9977"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/categories?post=9977"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/tags?post=9977"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}