Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

Transpose Matrix C#

public class Solution 
{
    public int[][] Transpose(int[][] matrix) 
    {
        var trans = GenerateArray(matrix[0].Length,matrix.Length,0);
        
        for(var i=0; i<matrix.Length;i++)
        {
            for(var j=0; j<matrix[0].Length;j++)
            {
                trans[j][i] = matrix[i][j];
            }
        }
        return trans;
    }
    public static T[][] GenerateArray<T>(int row, int Col,T value)
    {
        var arr = new T[row][];

        for (int i = 0; i < row; i++)
        {
            arr[i] = new T[Col];
            for (int j = 0; j < Col; j++)
            {
                arr[i][j] = value;
            }
        }
        return arr;
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# run a scheduled task 
Csharp :: c# nunit test case 
Csharp :: datatable in c# 
Csharp :: loop in c# 
Csharp :: truncate c# 
Csharp :: out c# 
Csharp :: list contains type c# 
Csharp :: admob unity 
Csharp :: adding to a dictionary class c# 
Csharp :: f# get last element of list 
Csharp :: C3 compare hour 
Csharp :: access server name or ip c# get 
Csharp :: Moq Unittest with ILogger 
Csharp :: c sharp xml prettier 
Csharp :: c# compare months 
Csharp :: How to cache database tables to prevent many database queries in Asp.net C# mvc 
Csharp :: c# Class instance 
Csharp :: Max upload size for ASP.MVC CORE website 
Csharp :: unity repeat coroutine 
Csharp :: how to get angular on visual studio mac 
Csharp :: get link element revit api 
Csharp :: edit database from datagridview with right click on data c# 
Csharp :: generate poco from db efcore 
Csharp :: back color for DateTimePicker control 
Csharp :: windows forms webbrowser navigate 
Csharp :: unity soundclip mix 
Csharp :: Filter list contents with predicate (anonymous method) 
Csharp :: c# short 
Csharp :: SETTING UP ARRAY FOR TEST SCORES IN C# 
Csharp :: C# Rev.ai transcription 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =