Created
November 28, 2022 13:51
-
-
Save catwell/d24810fc659072e8fcc1a179f9a95604 to your computer and use it in GitHub Desktop.
smlpth daily 2022-11-26
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def efficient_part2(input) | |
n = input.length | |
r = Array.new(n, 1) | |
p_up, p_down = 1, 1 | |
0.upto(n - 1) do |i| | |
j = n - i - 1 | |
r[i] *= p_up | |
r[j] *= p_down | |
p_up *= input[i] | |
p_down *= input[j] | |
end | |
r | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Potentiellement plus simple à comprendre, c'est la même chose sinon :