2315. 统计星号 - 力扣(LeetCode)
一、Java
- class Solution {
- public int countAsterisks(String s) {
- int cnt = 0;
- boolean flag = true;
- for(char c: s.toCharArray()) {
- if(c == '|') flag = !flag;
- else if(c == '*' && flag) cnt++;
- }
- return cnt;
- }
- }