当前位置:网站首页>Vowel substring in statistical string of leetcode simple problem
Vowel substring in statistical string of leetcode simple problem
2022-04-23 08:14:00 【·Starry Sea】
subject
Substring Is a continuous... In a string ( Non empty ) The character sequence of .
Vowel substring yes only By vowels (‘a’、‘e’、‘i’、‘o’ and ‘u’) A substring composed of , And it must contain All five vowel .
Give you a string word , Count and return word in Number of vowel substrings .
Example 1:
Input :word = “aeiouu”
Output :2
explain : The following is a list word Vowel substring in ( Bold part in italics ):
- “aeiouu”
- “aeiouu”
Example 2:
Input :word = “unicornarihan”
Output :0
explain :word Does not include 5 Kinds of vowels , So there will be no vowel substring .
Example 3:
Input :word = “cuaieuouac”
Output :7
explain : The following is a list word Vowel substring in ( Bold part in italics ):
- “cuaieuouac”
- “cuaieuouac”
- “cuaieuouac”
- “cuaieuouac”
- “cuaieuouac”
- “cuaieuouac”
- “cuaieuouac”
Example 4:
Input :word = “bbaeixoubb”
Output :0
explain : All substrings containing all five vowels contain consonants , So there is no vowel substring .
Tips :
1 <= word.length <= 100
word It's only made up of lowercase letters
source : Power button (LeetCode)
Their thinking
Traversal string , Enumerate from the current string to the right , If you can meet non repeated or repeated vowels all the way, and the type can reach 5 It's a string , If you break halfway, you will not jump out of the current enumeration directly , Proceed to the next enumeration , Start with the next character of the current character .
class Solution:
def countVowelSubstrings(self, word: str) -> int:
count,alpha=0,{
'a','e','i','o','u'}
for i in range(len(word)):
if word[i] in alpha:
temp={
word[i]}
else:
continue
for j in range(i+1,len(word)):
if word[j] in alpha:
temp.add(word[j])
else:
break
if len(temp)==5:
count+=1
return count
版权声明
本文为[·Starry Sea]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230701590418.html
边栏推荐
猜你喜欢
Weekly leetcode - 06 array topics 7 ~ 739 ~ 50 ~ offer 62 ~ 26 ~ 189 ~ 9
idea:使用easyYapi插件导出yapi接口
高精度焊接机械臂定位
Brief description of CPU
输入 “ net start mysql ”,出现 “ 发生系统错误 5。 拒绝访问 ” 。问题详解
[programming practice / embedded competition] learning record of embedded competition (II): picture streaming based on TCP
Go语学习笔记 - 异常处理 | 从零开始Go语言
vslam PPT
BUFFCTF文件中的秘密1
每周leetcode - 06 数组专题 7~739~50~offer 62~26~189~9
随机推荐
如何在SQL Server中导入excel数据,2019版
[untitled]
[极客大挑战 2019]Havefun1
Implementation of promise all
[programming practice / embedded competition] learning record of embedded competition (II): picture streaming based on TCP
网赚APP资源下载类网站源码
扎心了!一女子发朋友圈羡慕别人按时发工资被开除,连点赞的同事也一同被开除了...
[appium] encountered the problem of switching the H5 page embedded in the mobile phone during the test
PHP generates short links: convert numbers to letters and letters to numbers
mysql查询字符串类型的字段使用数字类型查询时问题
Hierarchical output binary tree
Concours de compétences en informatique en nuage - - première partie de l'environnement cloud privé openstack
【无标题】
Find the largest of 3 strings (no more than 20 characters per string).
Anti shake and throttling
Depth of binary tree
编译原理题-带答案
Principle of sentinel integrating Nacos to update data dynamically
3C裝配中的機械臂運動規劃
nn.Module类的讲解