Skip to content

Latest commit

 

History

History
20 lines (18 loc) · 415 Bytes

2315.md

File metadata and controls

20 lines (18 loc) · 415 Bytes

2315. Count Asterisks

Solution 1 (time O(n), space O(1))

class Solution(object):
    def countAsterisks(self, s):
        """
        :type s: str
        :rtype: int
        """
        ans = 0
        flag = 0
        for c in s:
            if flag == 0 and c == "*":
                ans += 1
            elif c == "|":
                flag = 1 - flag
        return ans