class Solution {
public:
vector<int> productExceptSelf(vector<int>& nums) {
vector<int>cnt(61, 0);
for (auto &x: nums) cnt[x + 30] += 1;
vector<int> ans;
for (auto &x: nums) {
int res = 1;
for (int i = 0; i <= 60; i++) {
int count = cnt[i];
int num = i - 30;
if (x == num) count -= 1;
res *= pow(num, count);
}
ans.push_back(res);
}
return ans;
}
};
Time Complexity: O(n)
Space: O(n)