当前位置:网站首页>力扣 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
边栏推荐
- Kirin Xin'an with heterogeneous integration cloud financial information and innovation solutions appeared at the 15th Hunan Financial Technology Exchange Conference
- 浏览积分设置的目的
- ASP.NET幼儿园连锁管理系统源码
- LeetCode力扣(剑指offer 36-39)36. 二叉搜索树与双向链表37. 序列化二叉树38. 字符串的排列39. 数组中出现次数超过一半的数字
- [sword finger offer] sword finger offer II 012 The sum of left and right subarrays is equal
- 注解。。。
- what‘s the meaning of inference
- How to buy bank financial products? Do you need a bank card?
- 怎么在手机上买股票开户 股票开户安全吗
- 使用高斯Redis实现二级索引
猜你喜欢

Install mysql8 for Linux X ultra detailed graphic tutorial

ASP. Net kindergarten chain management system source code

Matplotlib drawing 3D graphics

项目经理『面试八问』,看了等于会了

The project manager's "eight interview questions" is equal to a meeting

Interpretation of transpose convolution theory (input-output size analysis)

2022如何评估与选择低代码开发平台?

Kunpeng developer summit 2022 | Kirin Xin'an and Kunpeng jointly build a new ecosystem of computing industry

Openeuler prize catching activities, to participate in?

关于ssh登录时卡顿30s左右的问题调试处理
随机推荐
UCloud是基础云计算服务提供商
Openeuler prize catching activities, to participate in?
PMP每日一练 | 考试不迷路-7.7
[RT thread env tool installation]
Introduction to bit operation
编译器优化那些事儿(4):归纳变量
一张图深入的理解FP/FN/Precision/Recall
时间工具类
Notes...
9 原子操作类之18罗汉增强
R language ggplot2 visualization: use the ggdensity function of ggpubr package to visualize the packet density graph, and use stat_ overlay_ normal_ The density function superimposes the positive dist
el-upload上传组件的动态添加;el-upload动态上传文件;el-upload区分文件是哪个组件上传的。
谷歌seo外链Backlinks研究工具推荐
国家网信办公布《数据出境安全评估办法》:累计向境外提供10万人信息需申报
【STL】vector
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
tp6 实现佣金排行榜
IP tools
Simulate the implementation of string class
831. KMP string