题解:
按题意模拟
class Solution {
public int countAsterisks(String s) {
int n = s.length();
int res = 0;
// 是否不在竖线对之间
boolean flag = true;
for (int i = 0; i < n; i++) {
char c = s.charAt(i);
// 符合要求 答案++
if (c == '*' && flag) res++;
// 遇到左竖线,把flag 置为false, 遇到右竖线,把flag置为true
if (c == '|') flag = !flag;
}
return res;
}
}
标签:星号,res,2315,++,int,flag,统计,竖线
From: https://www.cnblogs.com/eiffelzero/p/17072054.html