LeetCode Biweekly Contest 20
問題文
省略
省略
C++に変換後のコードはこちら
#define main dummy_main
{}
#undef main
class Solution {
public:
int numberOfSubstrings(string s) {
ll res = 0;
int i, j, N = s.size();
int a = 0, b = 0, c = 0;
j = 0;
rep(i,N){
while(j < N && (a==0 || b==0 || c==0)){
if(s[j]=='a') a++;
if(s[j]=='b') b++;
if(s[j]=='c') c++;
j++;
}
if(a==0 || b==0 || c==0) break;
res += N - j + 1;
if(s[i]=='a') a--;
if(s[i]=='b') b--;
if(s[i]=='c') c--;
}
return res;
}
};
Current time: 2024年04月23日21時10分23秒
Last modified: 2020年02月23日07時02分43秒 (by laycrs)
Tags: Competitive_Programming_Incomplete LeetCode
トップページに戻る
Logged in as: unknown user (not login)