2315. Count Asterisks

problem

solution

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class Solution {
public:
int countAsterisks(string s) {
int ret = 0;
bool flag = false;
for(int i=0;i<s.size() ;i++){
if(s[i]=='|'){
i++;
while(i<s.size() && s[i]!='|') i++;
// i++;
}
else{
if(s[i]=='*') ret++;
// i++;
}
}
return ret;
}
};

analysis

  • time complexity O(n)
  • space complexity O(1)