C++ easy to understand solution with TC: O(sqrt(A))


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