当前位置:网站首页>Force buckle 2315 Statistical asterisk

Force buckle 2315 Statistical asterisk

2022-07-07 20:06:00 Tomorrowave

2315. Statistical asterisk

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|eet|co|*de|"
Output :2
explain : Characters not between vertical line pairs are bold and italicized , Get a string :"l|eet|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 .

Ideas :

matching

Code section

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
原网站

版权声明
本文为[Tomorrowave]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207071753356178.html