From 3a10d377ef58dd3259eaa0839b4cc226a5ac89bc Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Sun, 1 Dec 2024 18:03:05 +0000 Subject: [PATCH] break early once value in right surpasses k in left --- day-01/internal/two/solve.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/day-01/internal/two/solve.go b/day-01/internal/two/solve.go index 2d16959..405aad3 100644 --- a/day-01/internal/two/solve.go +++ b/day-01/internal/two/solve.go @@ -34,9 +34,10 @@ func Solve() (int, error) { var occurrences int for _, n := range right[indx:] { - if n == k { - occurrences++ + if n > k { + break } + occurrences++ } similarity += k * v * occurrences }