Class Solution

java.lang.Object
g2301_2400.s2315_count_asterisks.Solution

public class Solution extends Object
2315 - Count Asterisks.<p>Easy</p> <p>You are given a string <code>s</code>, where every <strong>two</strong> consecutive vertical bars <code>'|'</code> are grouped into a <strong>pair</strong>. In other words, the 1<sup>st</sup> and 2<sup>nd</sup> <code>'|'</code> make a pair, the 3<sup>rd</sup> and 4<sup>th</sup> <code>'|'</code> make a pair, and so forth.</p> <p>Return <em>the number of</em> <code>'*'</code> <em>in</em> <code>s</code><em>, <strong>excluding</strong> the</em> <code>'*'</code> <em>between each pair of</em> <code>'|'</code>.</p> <p><strong>Note</strong> that each <code>'|'</code> will belong to <strong>exactly</strong> one pair.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;l|*e*et|c**o|*de|&rdquo;</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> The considered characters are underlined: &ldquo;<ins>l</ins>|*e*et|<ins>c**o</ins>|*de|&rdquo;.</p> <p>The characters between the first and second &lsquo;|&rsquo; are excluded from the answer.</p> <p>Also, the characters between the third and fourth &lsquo;|&rsquo; are excluded from the answer. There are 2 asterisks considered. Therefore, we return 2.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;iamprogrammer&rdquo;</p> <p><strong>Output:</strong> 0</p> <p><strong>Explanation:</strong> In this example, there are no asterisks in s. Therefore, we return 0.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> s = &ldquo;yo|uar|e**|b|e***au|tifu|l&rdquo;</p> <p><strong>Output:</strong> 5</p> <p><strong>Explanation:</strong> The considered characters are underlined: &ldquo;<ins>yo</ins>|uar|<ins>e**</ins>|b|<ins>e***au</ins>|tifu|<ins>l</ins>&rdquo;.</p> <p>There are 5 asterisks considered. Therefore, we return 5.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= s.length <= 1000</code></li> <li><code>s</code> consists of lowercase English letters, vertical bars <code>'|'</code>, and asterisks <code>'*'</code>.</li> <li><code>s</code> contains an <strong>even</strong> number of vertical bars <code>'|'</code>.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • countAsterisks

      public int countAsterisks(String s)