This solution is of O(sqrt(N)) time complexity and without using "reverse" function for temporary array. How can I improvise it more?


#1

vector Solution::allFactors(int A) {
vector res;
vector temp;
if(A==1){
res.push_back(1);
}
else{
for (int i=1;ii<=A;i++){
if(A%i==0){
res.push_back(i);
if(i
i!=A)
temp.push_back(A/i);
}
}
res.insert(res.end(),temp.rbegin(),temp.rend());
}
return res;
}