当前位置:网站首页>力扣 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
边栏推荐
- Download from MySQL official website: mysql8 for Linux X Version (Graphic explanation)
- 一锅乱炖,npm、yarn cnpm常用命令合集
- AD域组策略管理
- mysql 的一些重要知识
- 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
- R语言dplyr包select函数、group_by函数、filter函数和do函数获取dataframe中指定因子变量中指定水平中特定数值数据列的值第三大的值
- ASP.NET体育馆综合会员管理系统源码,免费分享
- R language dplyr package select function, group_ The by function, filter function and do function obtain the third largest value of a specific numerical data column in a specified level in a specified
- LeetCode力扣(剑指offer 36-39)36. 二叉搜索树与双向链表37. 序列化二叉树38. 字符串的排列39. 数组中出现次数超过一半的数字
- Boot 和 Cloud 的版本选型
猜你喜欢
PMP每日一练 | 考试不迷路-7.7
【STL】vector
一张图深入的理解FP/FN/Precision/Recall
Classification automatique des cellules de modules photovoltaïques par défaut dans les images de lecture électronique - notes de lecture de thèse
mysql 的一些重要知识
华南X99平台打鸡血教程
Netease Yunxin participated in the preparation of the standard "real time audio and video service (RTC) basic capability requirements and evaluation methods" issued by the Chinese Academy of Communica
9 atomic operation class 18 Rohan enhancement
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
PMP對工作有益嗎?怎麼選擇靠譜平臺讓備考更省心省力!!!
随机推荐
R语言ggplot2可视化:使用ggpubr包的ggqqplot函数可视化QQ图(Quantile-Quantile plot)
Netease Yunxin participated in the preparation of the standard "real time audio and video service (RTC) basic capability requirements and evaluation methods" issued by the Chinese Academy of Communica
Sword finger offer II 013 Sum of two-dimensional submatrix
mock. JS returns an array from the optional data in the object array
CSDN语法说明
现在股票开户可以直接在网上开吗?安全吗。
Specify the version of OpenCV non-standard installation
MSE API学习
My creation anniversary
关于自身的一些安排
多个线程之间如何协同
Kunpeng developer summit 2022 | Kirin Xin'an and Kunpeng jointly build a new ecosystem of computing industry
国家网信办公布《数据出境安全评估办法》:累计向境外提供10万人信息需申报
IP 工具类
Tp6 realize Commission ranking
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
【剑指offer】剑指 Offer II 012. 左右两边子数组的和相等
Implement secondary index with Gaussian redis
mock.js从对象数组中任选数据返回一个数组
Browse the purpose of point setting