Skip to content

Commit e0f26d2

Browse files
authored
Create count-asterisks.py
1 parent c12a775 commit e0f26d2

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Python/count-asterisks.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
# string
5+
class Solution(object):
6+
def countAsterisks(self, s):
7+
"""
8+
:type s: str
9+
:rtype: int
10+
"""
11+
result = cnt = 0
12+
for c in s:
13+
if c == '|':
14+
cnt = (cnt+1)%2
15+
continue
16+
if c == '*' and cnt == 0:
17+
result += 1
18+
return result

0 commit comments

Comments
 (0)