C++ O(sqrt(A)) Solution


#1
vector<int> Solution::allFactors(int A) {
    vector<int> fac1, fac2;
    int i, lim = sqrt(A);
    for(i=1;i<lim;i++)
    {
        if(A%i==0)
        {
            fac1.push_back(i);
            fac2.push_back(A/i);
        }
    }
    
    if(A%lim == 0)
    {
        fac1.push_back(lim);
        if(lim != A/lim)
            fac1.push_back(A/lim);
    }
    
    
    for(int i=fac2.size()-1;i>=0;i--) fac1.push_back(fac2[i]);
    return fac1;
}