当前位置:网站首页>力扣 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
边栏推荐
- 转置卷积理论解释(输入输出大小分析)
- UCloud是基础云计算服务提供商
- My creation anniversary
- 831. KMP字符串
- How to cooperate among multiple threads
- Empowering smart power construction | Kirin Xin'an high availability cluster management system to ensure the continuity of users' key businesses
- R语言ggplot2可视化:使用ggpubr包的ggecdf函数可视化分组经验累积密度分布函数曲线、linetype参数指定不同分组曲线的线型
- ASP. Net gymnasium integrated member management system source code, free sharing
- 多个线程之间如何协同
- R language uses ggplot2 function to visualize the histogram distribution of counting target variables that need to build Poisson regression model, and analyzes the feasibility of building Poisson regr
猜你喜欢

9 atomic operation class 18 Rohan enhancement

论文解读(ValidUtil)《Rethinking the Setting of Semi-supervised Learning on Graphs》

Kirin Xin'an won the bid for the new generation dispatching project of State Grid!

多个线程之间如何协同

干货分享|DevExpress v22.1原版帮助文档下载集合

【RT-Thread env 工具安装】

爬虫实战(七):爬王者英雄图片

PMP對工作有益嗎?怎麼選擇靠譜平臺讓備考更省心省力!!!

Empowering smart power construction | Kirin Xin'an high availability cluster management system to ensure the continuity of users' key businesses

Sword finger offer II 013 Sum of two-dimensional submatrix
随机推荐
【RT-Thread env 工具安装】
8 CAS
torch. nn. functional. Pad (input, pad, mode= 'constant', value=none) record
tp6 实现佣金排行榜
Kirin Xin'an won the bid for the new generation dispatching project of State Grid!
【Confluence】JVM内存调整
mock.js从对象数组中任选数据返回一个数组
R language ggplot2 visualization: use the ggviolin function of ggpubr package to visualize the violin diagram, set the palette parameter to customize the filling color of violin diagrams at different
RESTAPI 版本控制策略【eolink 翻译】
Flink并行度和Slot详解
我的创作纪念日
Ucloud is a basic cloud computing service provider
项目经理『面试八问』,看了等于会了
编译器优化那些事儿(4):归纳变量
Simulate the implementation of string class
Make insurance more "safe"! Kirin Xin'an one cloud multi-core cloud desktop won the bid of China Life Insurance, helping the innovation and development of financial and insurance information technolog
Solve the problem of remote rviz error reporting
【STL】vector
R语言ggplot2可视化:使用ggpubr包的ggdensity函数可视化分组密度图、使用stat_overlay_normal_density函数为每个分组的密度图叠加正太分布曲线
openEuler 资源利用率提升之道 01:概论