明天反恐24前总统Logan要出来 (转载)# Joke - 肚皮舞运动
j*l
1 楼
You are given an array [a1 ... an] and we have to construct another array [
b1 To bn] where bi = a1 * a2 * ... * an / ai. You are allowed to use only
constant
space and the time complexity is O(n). No divisions are allowed.
解法是引入两个辅助数组
Si = a1 * a2 * ... * ai
Ti = ai * a(i+1) * ... * an
则bi = S[i-1] * T[i+1]
但是有题目要求的O(1)空间和O(n)时间的解法么?
b1 To bn] where bi = a1 * a2 * ... * an / ai. You are allowed to use only
constant
space and the time complexity is O(n). No divisions are allowed.
解法是引入两个辅助数组
Si = a1 * a2 * ... * ai
Ti = ai * a(i+1) * ... * an
则bi = S[i-1] * T[i+1]
但是有题目要求的O(1)空间和O(n)时间的解法么?