Untitled
user_9124840
plain_text
17 days ago
548 B
2
Indexable
Never
class Solution { public: vector<int> productExceptSelf(vector<int>& nums) { cin.tie(nullptr)->sync_with_stdio(0); int sz = nums.size(); vector<int> prefix(sz + 9, 1), suffix(sz + 9, 1); for (int i = 1; i <= sz; ++i) { prefix[i] = prefix[i - 1] * nums[i - 1]; suffix[sz - i + 1] = suffix[sz - i + 2] * nums[sz - i]; } for (int i = 1; i <= sz; ++i) { nums[i - 1] = prefix[i - 1] * suffix[i + 1]; } return nums; } };
Leave a Comment