15 August 2017

rotateImage

My solution:
int[][] rotateImage(int[][] a) 
{
    var list = new List<List<int>>();
    foreach (var t in a)
    {
        var column = new List<int>();
        for (var j = 0; j < a[0].Length; j++)
            column.Add(t[j]);

        list.Add(column);
    }

    var solution = new int[a.Length][];
    for (var i = 0; i < a.Length; i++)
        solution[i] = new int[a.Length];

    for (var i = 0; i < a.Length; i++)
        for (var j = 0; j < a[0].Length; j++)
            solution[i][j] = list[a.Length - 1 - j][i];

    return solution;
}

Previous Next