diff --git a/solution/1400-1499/1424.Diagonal Traverse II/README.md b/solution/1400-1499/1424.Diagonal Traverse II/README.md index cf236d358f553..5ec5396e50603 100644 --- a/solution/1400-1499/1424.Diagonal Traverse II/README.md +++ b/solution/1400-1499/1424.Diagonal Traverse II/README.md @@ -151,6 +151,27 @@ func findDiagonalOrder(nums [][]int) []int { } ``` +### **C#** + +```cs +public class Solution { + public int[] FindDiagonalOrder(IList> nums) { + List arr = new List(); + for (int i = 0; i < nums.Count; ++i) { + for (int j = 0; j < nums[i].Count; ++j) { + arr.Add(new int[] { i + j, j, nums[i][j] }); + } + } + arr.Sort((a, b) => a[0] == b[0] ? a[1] - b[1] : a[0] - b[0]); + int[] ans = new int[arr.Count]; + for (int i = 0; i < arr.Count; ++i) { + ans[i] = arr[i][2]; + } + return ans; + } +} +``` + ### **...** ``` diff --git a/solution/1400-1499/1424.Diagonal Traverse II/README_EN.md b/solution/1400-1499/1424.Diagonal Traverse II/README_EN.md index 2a907fdc4cb5f..ab7d28368a4d3 100644 --- a/solution/1400-1499/1424.Diagonal Traverse II/README_EN.md +++ b/solution/1400-1499/1424.Diagonal Traverse II/README_EN.md @@ -115,6 +115,27 @@ func findDiagonalOrder(nums [][]int) []int { } ``` +### **C#** + +```cs +public class Solution { + public int[] FindDiagonalOrder(IList> nums) { + List arr = new List(); + for (int i = 0; i < nums.Count; ++i) { + for (int j = 0; j < nums[i].Count; ++j) { + arr.Add(new int[] { i + j, j, nums[i][j] }); + } + } + arr.Sort((a, b) => a[0] == b[0] ? a[1] - b[1] : a[0] - b[0]); + int[] ans = new int[arr.Count]; + for (int i = 0; i < arr.Count; ++i) { + ans[i] = arr[i][2]; + } + return ans; + } +} +``` + ### **...** ``` diff --git a/solution/1400-1499/1424.Diagonal Traverse II/Solution.cs b/solution/1400-1499/1424.Diagonal Traverse II/Solution.cs new file mode 100644 index 0000000000000..76d2aac11d158 --- /dev/null +++ b/solution/1400-1499/1424.Diagonal Traverse II/Solution.cs @@ -0,0 +1,16 @@ +public class Solution { + public int[] FindDiagonalOrder(IList> nums) { + List arr = new List(); + for (int i = 0; i < nums.Count; ++i) { + for (int j = 0; j < nums[i].Count; ++j) { + arr.Add(new int[] { i + j, j, nums[i][j] }); + } + } + arr.Sort((a, b) => a[0] == b[0] ? a[1] - b[1] : a[0] - b[0]); + int[] ans = new int[arr.Count]; + for (int i = 0; i < arr.Count; ++i) { + ans[i] = arr[i][2]; + } + return ans; + } +}