L
and R
of the same length as the input array nums
.L[0]
to 1 because there are no elements to the left of the first element.L
array by setting L[i] = L[i - 1] * nums[i - 1]
for i
from 1 to n - 1
.R[n - 1]
to 1 because there are no elements to the right of the last element.R
array by setting R[i] = R[i + 1] * nums[i + 1]
for i
from n - 2
down to 0.nums
.answer[i] = L[i] * R[i]
for each i
.