Image Rotate / Rotate Matrix - Brute Force Method - JAVA


#1
    public void rotate(ArrayList<ArrayList<Integer>> arr) {
    int k = arr.size() - 1;

    int[][] mat = new int[arr.size()][arr.size()];

    for (int i = 0; i < arr.size(); i++) {
        for (int j = 0; j < arr.size(); j++) {
            mat[j][k] = arr.get(i).get(j);
        }
        k--;
    }

    for (int i = 0; i < arr.size(); i++) {
        ArrayList<Integer> list = new ArrayList<>(arr.size());
        for (int j = 0; j < arr.size(); j++) {
            list.add(mat[i][j]);
            arr.set(i, list);
        }
    }
}