Count Asterisks LeetCode solution in C++
1/*21.) Maintain a counter to store the '|'32.) After every even no. of '|' count the asteriks.4*/5class Solution {6public:7int countAsterisks(string s) {8int ans = 0;910// count of no. of '|'11int cnt = 0;1213for (int i = 0; i < s.size(); i++) {14// if count is even then count the asteriks15if (cnt % 2 == 0) {16if (s[i] == '*') ans++;17}18if (s[i] == '|') cnt++;19}20return ans;21}22};