Java Solution: using temp list to hold the bigger con-factors and appending them back in reverse order


#1

Java Solution: using temp list to hold the bigger co-factors and appending them back in reverse order.
`public class Solution {

public ArrayList<Integer> allFactors(int A) {
    
    ArrayList<Integer> results = new ArrayList<>();
    ArrayList<Integer> higher = new ArrayList<>();
    
    int sqrRootA = (int) Math.sqrt(A);
    for(int i = 1; i <= sqrRootA; i++) {
        if (A % i == 0) {
            results.add(i);
            
            if (A/i != i) {//not the squareroot
                higher.add(A/i);
            }
        }
    }
    
    for (int i = higher.size() - 1; i >= 0; i--) {
        results.add(higher.get(i));
    }
    return results;
}

}
`