标签:line length family code 一个 mil -- ble 思路
1 class Solution { 2 public: 3 //B[i]=A[0]*A[1]*...*A[i-1]*A[i+1]*...*A[n-1] 4 //从左到右算 B[i]=A[0]*A[1]*...*A[i-1] 5 //从右到左算B[i]*=A[i+1]*...*A[n-1] 6 //C[i] = C[i-1] * A[i-1] 7 //D[i] = D[i+1] * A[i+1]; 8 vector<int> multiply(const vector<int>& A) { 9 int length = A.size(); 10 vector<int> B(length); 11 B[0] = 1; 12 for(int i=1;i<length;i++) 13 { 14 B[i] = B[i-1] * A[i-1]; 15 } 16 double temp = 1; 17 for(int i=length-2;i>=0;--i) 18 { 19 temp = temp * A[i+1]; 20 B[i] *= temp; 21 } 22 return B; 23 } 24 };
标签:line length family code 一个 mil -- ble 思路
原文地址:http://www.cnblogs.com/qqky/p/7084605.html