当前位置:网站首页>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
边栏推荐
- 青苹果影视系统源码 影视聚合 影视导航 影视点播网站源码
- Compiling principle questions - with answers
- Positioning and decoration style
- 1216_ MISRA_ C standard learning notes_ Rule requirements for control flow
- Why are there 1px problems? How?
- C语言学习记录——삼십팔 字符串函数使用和剖析(2)
- Go语学习笔记 - 异常处理 | 从零开始Go语言
- 搜一下导航完整程序源码
- 1216_MISRA_C规范学习笔记_控制流的规则要求
- Implementation of new
猜你喜欢

Cloud computing skills competition -- Part 2 of openstack private cloud environment

谈谈那些基础但不简单的股票数据

Ubuntu安装Mysql并查询平均成绩

利用Js实现一个千分位

Anti shake and throttling

Somme numérique de la chaîne de calcul pour un problème simple de leetcode

LeetCode 1611. 使整数变为 0 的最少操作次数

LeetCode中等题之旋转函数

一款拥有漂亮外表的Typecho简洁主题_Scarfskin 源码下载

高精度焊接机械臂定位
随机推荐
常用正则表达式
Upload labs range practice
智能名片小程序名片详情页功能实现关键代码
nn.Module类的讲解
刨析——浏览器如何工作
一篇文章看懂变量提升(hoisting)
The following program deletes n consecutive words starting from the ith character from the string str
The whole house intelligence bet by the giant is driving the "self revolution" of Hisense, Huawei and Xiaomi
多目视觉SLAM
Quick rehearsal exercise
C语言学习记录——삼십팔 字符串函数使用和剖析(2)
Guoji Beisheng openstack container cloud environment construction
Find the largest of 3 strings (no more than 20 characters per string).
Hierarchical output binary tree
Move layout (Flex layout, viewport label)
每周leetcode - 06 数组专题 7~739~50~offer 62~26~189~9
AAAI 2022 recruit speakers!!
Implementation of new
Brief description of CPU
利用Js实现一个千分位