当前位置:网站首页>LeetCode 2315. Statistical asterisk (string)
LeetCode 2315. Statistical asterisk (string)
2022-07-19 10:51:00 【Michael Amin】
List of articles
1. subject
Give you a string s , Every time Two Continuous vertical line '|' by a pair .
In other words , The first and the second '|' It's a couple , The third and the fourth '|' It's a couple , And so on .
Please return be not in Between vertical line pairs ,s in '*' Number of .
Be careful , Each vertical line '|' Metropolis just Belong to a pair .
Example 1:
Input :s = "l|*e*et|c**o|*de|"
Output :2
explain : Characters not between vertical line pairs are bold and italicized , Get a string :"l|*e*et|c**o|*de|" .
The first and second vertical lines '|' Characters between are not included in the answer .
meanwhile , The third and fourth vertical lines '|' Characters between are not included in the answer .
There is a total of... Between vertical line pairs 2 asterisk , So we go back to 2 .
Example 2:
Input :s = "iamprogrammer"
Output :0
explain : In this case ,s There is no asterisk in . So back 0 .
Example 3:
Input :s = "yo|uar|e**|b|e***au|tifu|l"
Output :5
explain : Characters to be considered are bold and italicized :"yo|uar|e**|b|e***au|tifu|l" . There is a total of... Between vertical line pairs 5 asterisk . So we go back to 5 .
Tips :
1 <= s.length <= 1000
s Only lowercase letters , A vertical bar '|' And asterisk '*' .
s contain even numbers Vertical lines '|' .
source : Power button (LeetCode) link :https://leetcode.cn/problems/count-asterisks
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
2. Problem solving
- according to
|Cut open , Take outindex It's evenSubstring statistics
class Solution:
def countAsterisks(self, s: str) -> int:
w = s.split('|')
ans = 0
for i in range(0, len(w), 2):
ans += w[i].count('*')
return ans
28 ms 14.9 MB Python3
my CSDN Blog address https://michael.blog.csdn.net/
Long click or sweep code pay attention to my official account (Michael amin ), Come on together 、 Learn together !
边栏推荐
- [LeetCode周赛复盘] 第 302 场周赛20220717
- 关于hping打流测试工具
- SAP AppGyver 的 Universal Theme System 使用介绍
- leetcode-08
- 【手写数字识别】基于Lenet网络实现手写数字识别附matlab代码
- vulnhub inclusiveness: 1
- 6G全域融合网络展望
- Vérification logique complexe personnalisée lors de l'ajout et de la modification - 2022 nouvel élément
- IP SAN拥有独立的文件系统,应用服务器通过网络共享协议访问到IP SAN后,可以对文件系统中的文件进行读写操作
- 发明闪存能赚多少钱?这是一个日本的狗血故事
猜你喜欢

【在vivado中调ila IP核】

Pytoch framework learning record 1 cifar-10 classification

Win10安装Apache Jena 3.17

JSP based novel writing and creation website

vulnhub inclusiveness: 1

LeetCode 2335. 装满杯子需要的最短总时长

Design of the multi live architecture in different places of the king glory mall

因果学习将开启下一代AI浪潮?九章云极DataCanvas正式发布YLearn因果学习开源项目

电商销售数据分析与预测(日期数据统计、按天统计、按月统计)

【手写数字识别】基于Lenet网络实现手写数字识别附matlab代码
随机推荐
Pytorch与权重衰减(L2范数)
Autojs learning - multi function treasure chest - bottom
unity3d中的旋转
[Acwing] 第 60 场周赛 C-AcWing 4496. 吃水果
Pytorch手动实现多层感知机
【在vivado中调ila IP核】
leetcode-08
线程池原理
Common collection properties
37. Flex layout
About hping streaming test tool
(一)了解MySQL
新增、修改操作时自定义复杂逻辑校验-2022新项目
Pytorch学习记录2 线性回归(Tensor,Variable)
LeetCode 2331. 计算布尔二叉树的值(树的遍历)
开发第一个Flink应用
6G中的卫星通信高效天基计算技术
过拟合与欠拟合
JSP based novel writing and creation website
Find balanced binary tree