当前位置:网站首页>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
边栏推荐
- How does feign integrate hystrix
- BUUCTF [极客大挑战 2019]EasySQL1
- 数据库之Mysql——概述安装篇
- NFT ecological development of Ignis public chain: unicorn Donation and development of Art
- [Effective Go 中文翻译] 第一篇
- dmp引擎工作总结(2021,光剑)
- yum源仓库本地搭建的两种方法
- Go语学习笔记 - 语言接口 | 从零开始Go语言
- [untitled]
- Kubernetes in browser and IDE | interactive learning platform killercoda
猜你喜欢
vivo,硬件安全的爱与雷霆
1216_ MISRA_ C standard learning notes_ Rule requirements for control flow
Smart business card applet business card details page function implementation key code
[untitled]
The whole house intelligence bet by the giant is driving the "self revolution" of Hisense, Huawei and Xiaomi
AAAI 2022招募讲者啦!!
惨了,搞坏了领导的机密文件,吐血分享备份文件的代码技巧
Anti shake and throttling
数据安全问题已成隐患,看vivo如何让“用户数据”重新披甲
CSV Column Extract列提取
随机推荐
Talking about distributed storage from ES, mongodb, redis and rocketmq
CSV Column Extract列提取
高精度焊接机械臂定位
常用正则表达式
利用Js实现一个千分位
NIH降血脂指南《your guide to lowering your Cholesterol with TLC》笔记(持续更新中)
Alibaba sentinel learning QA
LeetCode简单题之统计字符串中的元音子字符串
How to import Excel data in SQL server, 2019 Edition
Solidity IDE Remix中文版使用手册
How does feign integrate hystrix
雲計算技能大賽 -- openstack私有雲環境 第一部分
如何在SQL Server中导入excel数据,2019版
简述CPU
LeetCoed18. Sum of four numbers
vslam PPT
简述存储器的分级策略
数据库之Mysql——概述安装篇
Asynchronous learning
谈谈那些基础但不简单的股票数据