Give you a string s , Every two consecutive vertical lines ‘|’ It's a couple . 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 not between vertical line pairs ,s in ‘*’ Number of .
Be careful , Each vertical line ‘|’ Will just belong to a pair .
Input :s = “l|eet|co|*de|"
Output :2
explain : Characters not between vertical line pairs are bold and italicized , Get a string :"l|eet|co|*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 .
Input :s = “iamprogrammer”
Output :0
explain : In this case ,s There is no asterisk in . So back 0 .
Input :s = “yo|uar|e**|b|eau|tifu|l"
Output :5
explain : Characters to be considered are bold and italicized :"yo|uar|e|b|e**au|tifu|l” . There is a total of... Between vertical line pairs 5 asterisk . So we go back to 5 .
1 <= s.length <= 1000
s Only lowercase letters , A vertical bar ‘|’ And asterisk ‘*’ .
s contain even numbers Vertical lines ‘|’ .
class Solution:
def countAsterisks(self, s: str) -> int:
count = 0
ans = 0
for i in s:
if i == '|':
count += 1
if count % 2 == 0 and i == '*':
ans += 1
return ans