C++ solution without using sort


#1

vector Solution::allFactors(int A) {
vector v;
v = {1,A};
for(int i = 2;i<=sqrt(A);i++)
{
int n = v.size();
if(A % i == 0)
{
v.insert(v.begin()+n/2, i);
if(i != sqrt(A))
{
v.insert(v.end()-n/2, A/i);
}
}

}
if(A == 1)
{
    v.pop_back();
}
return v;

}