Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i]. • څ㟬Ұݸ࠷গ༗ၷݸᏐࣈత Array nums, ճၚҰݸ Array output, output[i] ԙ nums ཫ໘আྃ nums[i] Ҏ֎ॴ༗త Ꮠࣈ૬ငɻ
complexity? (Note: The output array does not count as extra space for the purpose of space complexity analysis.) • Ճɿ ༗ᔒ༗㭎๏༻ݻఆతۭؒबಘ౸݁Ռʁʢ༌ग़༻త Array ࢉੋݻఆۭؒʣ
var frontProd:[Int] = [1] for n in nums { frontProd.append(frontProd.last! * n) } frontProd.removeLast() var backProd:[Int] = [1] for n in nums.reversed() { backProd.append(backProd.last! * n) } backProd.reverse() backProd.removeFirst() var res:[Int] = [] for idx in 0..<nums.count { res.append(frontProd[idx] * backProd[idx]) } return res } } ࣌ؒෳᯑ: O(n) ۭؒෳᯑ: O(n)