Leetcode Problem 2315. Count Asterisks

2315. Count Asterisks

Leetcode Solutions

Toggle Flag Approach

  1. Initialize a counter count to 0 for counting asterisks.
  2. Initialize a boolean flag betweenBars to False.
  3. Iterate through each character ch in the string s. a. If ch is a vertical bar '|', toggle the betweenBars flag. b. If ch is an asterisk '*' and betweenBars is False, increment the count.
  4. Return the value of count.
UML Thumbnail

Split and Count Approach

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...