i am trying to solve this problem
Given an m x n matrix mat, return an array of all the elements of the array in a diagonal order.
Input: mat = [[1,2,3],[4,5,6],[7,8,9]]
Output: [1,2,4,7,5,3,6,8,9]
i wrote this code on my vs and it works fine but when i submit on leetcode i get compile error
Line 12: Char 24: error CS0022: Wrong number of indices inside []; expected 1 (in Solution.cs)
here is my code i didn't check the solution provided on leetcode yet
...
public class Solution {
public int[] FindDiagonalOrder(int[][] mat) {
int rows = mat.GetUpperBound(0) + 1;
int cols = mat.GetUpperBound(1) + 1;
int[] res = new int[rows * cols];
int i = 0, j = 0,c=0;
while (i < rows && j < cols)
{
while (i >= 0 && j < cols)
{
res[c]=mat[i,j];
i--;
j++;
c++;
}
i++;
j--;
if (j == cols - 1)
i++;
else if (i == 0)
j++;
while (i < rows && j >= 0)
{
res[c] = mat[i, j];
i++;
j--;
c++;
}
i--;
j++;
if (i == rows - 1)
j++;
else if(j == 0)
i++;
}
return res;
}}
...