AcWing——3624. 三值字符串
双指针解法
#include<iostream>
#include<unordered_map>
using namespace std;
int main() {
int n; cin >> n;
while(n--){
unordered_map<char, int> tree;
string s; cin >> s;
int ans = 0x7fffffff;
for(int i = 0, j = 0; j < (int)s.size(); j++){
tree[s[j]]++;
while(tree[s[i]] > 1) tree[s[i++]]--;
if(tree['1'] && tree['2'] && tree['3'])
ans = min(ans, j-i+1);
}
if(ans == 0x7fffffff) cout << 0 << '\n';
else cout << ans << '\n';
}
return 0;
}