Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

Transpose Matrix CSharp

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 :: matrix transpose 
Csharp :: ado stands for 
Csharp :: C# long 
Csharp :: exception is null c# 
Csharp :: entity framework id not auto increment 
Csharp :: c# double 
Csharp :: static property in c# 
Csharp :: what are delegates and how to use them c# 
Csharp :: send mail c# 
Csharp :: flyt wordpress fra localserver 
Csharp :: c# quick "is" "as" 
Csharp :: c# generate insert statement from object 
Csharp :: IOException: Failed to prepare target build directory. Is a built game instance running? UnityEditor.WindowsStandalone.WindowsDesktopStandalonePostProcessor.DeleteDestination (UnityEditor.Modules.BuildPostProcessArgs args) 
Csharp :: c# null check 
Csharp :: aspnet for loop 
Csharp :: no cameras rendering unity 
Csharp :: nuget Microsoft.EntityFrameworkCore.InMemory": "1.0.0" 
Csharp :: c# ilogger for inherited class 
Csharp :: asp.net session empty cehck 
Csharp :: c# XmlElement from string 
Csharp :: C# program to find sum of array elements 
Csharp :: blazor wasm roles not working 
Csharp :: select every second row in html table 
Csharp :: how to show messagebox 
Csharp :: epplus how to align text to right 
Csharp :: unity player movement script 3d 
Csharp :: unity phone vibration 
Csharp :: C# string array in setter 
Csharp :: when should i use struct rather than class in c# 
Csharp :: scroll two divs simultaneously site:stackoverflow.com 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =