Even faster
This commit is contained in:
parent
386f764fbd
commit
3ef5039528
|
@ -76,25 +76,24 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
// -- Helpers --
|
// -- Helpers --
|
||||||
fn is_start_marker((index, window): (usize, &[u8])) -> Option<usize> {
|
fn is_start_marker(window: &[u8]) -> bool {
|
||||||
for i in 0..window.len() {
|
for i in 0..window.len() {
|
||||||
for j in i+1..window.len() {
|
for j in i+1..window.len() {
|
||||||
if window[i] == window[j] {
|
if window[i] == window[j] {
|
||||||
return None;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Some(index + window.len());
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn solution(input: &str, length: usize) -> usize {
|
fn solution(input: &str, length: usize) -> usize {
|
||||||
input
|
input
|
||||||
.as_bytes()
|
.as_bytes()
|
||||||
.windows(length)
|
.windows(length)
|
||||||
.enumerate()
|
.position(is_start_marker)
|
||||||
.find_map(is_start_marker)
|
.expect("Invalid input") + length
|
||||||
.expect("Invalid input")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -- Solution --
|
// -- Solution --
|
||||||
|
|
Loading…
Reference in New Issue
Block a user