标签:
1 class Solution { 2 public: 3 vector<int> multiply(const vector<int>& A) { 4 vector<int> result,result1,result2; 5 if (A.size() == 0) 6 return result; 7 if(A.size() == 1) 8 { 9 result.push_back(0); 10 return result; 11 } 12 result1.push_back(1); 13 int len = A.size(); 14 for(int i = 1 ;i < len ;++i) 15 { 16 result1.push_back(result1[i-1]*A[i-1]); 17 } 18 for(int i = 0 ;i < len ;++i) 19 { 20 result2.push_back(1); 21 } 22 for(int i = len - 2 ;i >= 0 ; --i) 23 { 24 result2[i] = result2[i+1]*A[i+1]; 25 } 26 for(int i = 0 ;i < len ;++i) 27 { 28 result.push_back(result1[i]*result2[i]); 29 } 30 return result; 31 } 32 };
标签:
原文地址:http://www.cnblogs.com/xiaoyesoso/p/5161940.html