3 ms·
One small thing: // Turn on bits as they enter the window set ^= 1 << (s[i] as u32 - 'a' as u32); // Turn off bits as they leave the w
by twic 4y ago
One small thing:
// Turn on bits as they enter the window
set ^= 1 << (s[i] as u32 - 'a' as u32);
// Turn off bits as they leave the window
if i >= window_size {
set ^= 1 << (s[i - window_size] as u32 - 'a' as u32);
}
"turn on" and "turn off" actually mean "flip", right? Each bit is not a present/not present flag, it's the parity of the count of number of occurrences. Which still works, because of the "counting how many characters appear an odd number of times in a window" thing.