题解 | #字符串#
字符串
https://ac.nowcoder.com/acm/problem/18386
#include
using namespace std;
int st[100];
int main() { string s; cin >> s;
int l, r, cnt = 0, ret;
for(r = 0; r < s.size(); r++)
{
st[s[r] - 'a'] ++;
if(st[s[r] - 'a'] == 1) cnt ++;
if(cnt == 26) break;
}
ret = r, s += "Z";
for(l = 0; l < s.size() && r < s.size(); l++)
{
//cout << l;
st[s[l] - 'a'] --;
while (st[s[l] - 'a'] == 0 && r < s.size() - 1)
{
r++, st[s[r] - 'a'] ++;
}
//cout << l << ' ' << r << ' ' << st[s[l] - 'a'] << endl;
if(r == s.size() - 1 && st[s[l] - 'a'] == 0) break;
if(st[l] - 'a' > 0) ret = min(ret, r - l);
}
cout << ret;
return 0;
} 不知道错误在哪里 orz