What do you think of my solution?


#1

public ArrayList rotateArray(ArrayList A, int B) {

ArrayList<Integer> ret = null;
    int turn = 1;
    
    while(turn <= B){
        
        ret = new ArrayList<Integer>();
        
        int first = A.get(0);
        for(int i = 0; i < A.size() - 1; i++){
            ret.add(i, A.get(i + 1));
        }
        
        ret.add(A.size() - 1, first);
        
        turn++;    

        A = ret;
    }
    
    return A;
    
}

The time complexity is currently O(n^2). please suggest improvements.