当前位置:网站首页>力扣 2315.统计星号
力扣 2315.统计星号
2022-07-07 17:53:00 【Tomorrowave】
2315.统计星号
给你一个字符串 s ,每 两个 连续竖线 ‘|’ 为 一对 。换言之,第一个和第二个 ‘|’ 为一对,第三个和第四个 ‘|’ 为一对,以此类推。
请你返回 不在 竖线对之间,s 中 ‘*’ 的数目。
注意,每个竖线 ‘|’ 都会 恰好 属于一个对。
示例 1:
输入:s = “l|eet|co|*de|"
输出:2
解释:不在竖线对之间的字符加粗加斜体后,得到字符串:"l|eet|co|*de|” 。
第一和第二条竖线 ‘|’ 之间的字符不计入答案。
同时,第三条和第四条竖线 ‘|’ 之间的字符也不计入答案。
不在竖线对之间总共有 2 个星号,所以我们返回 2 。
思路:
匹配
代码部分
class Solution(object):
def countAsterisks(self, s):
""" :type s: str :rtype: int """
cnt=0
c=0
for i in s:
if i=='|':
cnt+=1
elif cnt%2==0 and i=='*':
c+=1
return c
边栏推荐
- J ü rgen schmidhub reviews the 25th anniversary of LSTM papers: long short term memory All computable metaverses. Hierarchical reinforcement learning (RL). Meta-RL. Abstractions in generative adversar
- 强化学习-学习笔记8 | Q-learning
- Redis master-slave and sentinel master-slave switchover are built step by step
- 【Confluence】JVM内存调整
- Browse the purpose of point setting
- LeetCode力扣(剑指offer 36-39)36. 二叉搜索树与双向链表37. 序列化二叉树38. 字符串的排列39. 数组中出现次数超过一半的数字
- Install mysql8 for Linux X ultra detailed graphic tutorial
- PMP practice once a day | don't get lost in the exam -7.7
- 剑指 Offer II 013. 二维子矩阵的和
- How to buy bank financial products? Do you need a bank card?
猜你喜欢

开源重器!九章云极DataCanvas公司YLearn因果学习开源项目即将发布!

RESTAPI 版本控制策略【eolink 翻译】

Navicat连接2002 - Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘解决

Automatic classification of defective photovoltaic module cells in electroluminescence images-論文閱讀筆記

el-upload上传组件的动态添加;el-upload动态上传文件;el-upload区分文件是哪个组件上传的。

PMP每日一练 | 考试不迷路-7.7

PMP practice once a day | don't get lost in the exam -7.7

9 atomic operation class 18 Rohan enhancement

关于cv2.dnn.readNetFromONNX(path)就报ERROR during processing node with 3 inputs and 1 outputs的解决过程【独家发布】

Cloud 组件发展升级
随机推荐
Training IX basic configuration of network services
Automatic classification of defective photovoltaic module cells in electroluminescence images-论文阅读笔记
mock.js从对象数组中任选数据返回一个数组
R语言ggplot2可视化:使用ggpubr包的ggviolin函数可视化小提琴图、设置palette参数自定义不同水平小提琴图的填充色、add参数在小提琴图添加箱图
【STL】vector
Openeuler prize catching activities, to participate in?
转置卷积理论解释(输入输出大小分析)
how to prove compiler‘s correctness
浏览积分设置的目的
How to buy bank financial products? Do you need a bank card?
LC: string conversion integer (ATOI) + appearance sequence + longest common prefix
The strength index of specialized and new software development enterprises was released, and Kirin Xin'an was honored on the list
R语言fpc包的dbscan函数对数据进行密度聚类分析、查看所有样本的聚类标签、table函数计算聚类簇标签与实际标签构成的二维列联表
841. String hash
PMP每日一练 | 考试不迷路-7.7
Interpretation of transpose convolution theory (input-output size analysis)
Compiler optimization (4): inductive variables
Simulate the implementation of string class
模拟实现string类
编译器优化那些事儿(4):归纳变量