classSolution: defcountAsterisks(self, s: str) -> int: stack = True flag = 0 for i in s: if stack: if i == '*': flag += 1 if i == '|'and stack: stack = False elif i == '|'andnot stack: stack = True return flag
ylq
1 2 3 4 5 6 7 8 9
classSolution: defcountAsterisks(self, s: str) -> int: count1, count2 = 0, 0 for i inrange(len(s)): if s[i] == '|': count1 += 1 if count1 % 2 == 0and s[i] == '*': count2 += 1 return count2