leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0238.cpp (395B)


0 class Solution {
1 public:
2 vector<int> productExceptSelf(vector<int> &nums) {
3 int n = nums.size();
4 vector<int> answer(n, 1);
6 int acc1 = 1, acc2 = 1;
7 for (int i = 0, j = n - 1; i < n; i++, j--) {
8 answer[i] *= acc1;
9 answer[j] *= acc2;
10 acc1 *= nums[i];
11 acc2 *= nums[j];
12 }
14 return answer;
15 }
16 };