题目描述 given an array n ms of n integers where n  1, ret rn an array o tp t s ch that o tp t[i] is eq al to the prod ct of all the elements of n ms except n ms[i]. example: inp t: [1,2,3,4] o tp t: [24,12,8,6] note: please solve it witho t division and in o(n). follow p: co ld yo solve it with constant space complexity? (the o tp t array does not co nt as extra space for the p rpose of space complexity analysis.) qiang的思路 class sol tion: def prod ctexceptself(self, n ms: list[int]) - list[int]: res = [1 for _ in range(len(n ms))] for i in range(1, len(n ms)): res[i] = res[i-1] * n ms[i-1] tmp = 1 for i in range(len(n ms)-2, -1, -1): tmp = tmp * n ms[i+1] res[i] = tmp * res[i] ret rn res class sol tion { p blic: vectorint prod ctexceptself(vectorint& n ms) { vectorint res(n ms.size); res[0]=1; for(int i=1; in ms.size; i) res[i]=res[i-1]*n ms[i-1]; int tmp=1; for(int i=n ms.size-2; i=0; i--){ tmp*=n ms[i+1]; res[i]*=tmp; } ret rn res; } };