Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

Transpose Matrix C Sharp

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 :: DateTime restrictions 
Csharp :: linq syntax 
Csharp :: animation not playing unity 
Csharp :: asp.net web forms 
Csharp :: 2d explosion unity 
Csharp :: create a file in the directory of the exe and write to it c# 
Csharp :: string.format() c# 
Csharp :: sqlite execute 
Csharp :: while loop in c# 
Csharp :: c# delete object 
Csharp :: error cs1585 unity 
Csharp :: C# ToCsv Extension Method 
Csharp :: How do I call a string inside a different class 
Csharp :: dotnet core clickable row 
Csharp :: Read csv file into wpf C# 
Csharp :: c# on alt + f4 
Csharp :: call class c# 
Csharp :: how to change argument of function in f# 
Csharp :: how to turn the textbox into char in windows forms 
Csharp :: c# base vs this 
Csharp :: delegate 
Csharp :: how to change font text mesh pro 
Csharp :: hierachical table to c# class 
Csharp :: générer un nombre aléatoire en c# 
Csharp :: take out substring from string 
Csharp :: take the last 50 from array c# 
Csharp :: opération inter-threads non valide 
Csharp :: Difference between IHostingEnvironment and IWebHostEnvironment ? 
Csharp :: c# core deploy on gcp with powershell 
Csharp :: WPF TextBox input to All Caps 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =