#2315

Count Asterisks

newbie · 155 · lc easy +14 · verified · 83.3% accepted · 681 likes · top 95%

Description

You are given a string s where pairs of consecutive '|' characters are grouped together — the 1st and 2nd '|' form the first pair, the 3rd and 4th form the second pair, and so on.

Return the number of '*' characters that lie outside every '|' pair.

Note: every '|' belongs to exactly one pair.

Example 1:

Input: s = "l|*e*et|c**o|*de|"
Output: 2
Explanation: The considered characters are underlined: "l|*e*et|c**o|*de|".
The characters between the first and second '|' are excluded from the answer.
Also, the characters between the third and fourth '|' are excluded from the answer.
There are 2 asterisks considered. Therefore, we return 2.

Example 2:

Input: s = "iamprogrammer"
Output: 0
Explanation: In this example, there are no asterisks in s. Therefore, we return 0.

Example 3:

Input: s = "yo|uar|e**|b|e***au|tifu|l"
Output: 5
Explanation: The considered characters are underlined: "yo|uar|e**|b|e***au|tifu|l". There are 5 asterisks considered. Therefore, we return 5.

Code

1
2
3