首页 > 代码库 > leetcode378

leetcode378

public class Solution {
    public int KthSmallest(int[,] matrix, int k) {
        var row = matrix.GetLength(0);
            var col = matrix.GetLength(1);

            var list = new List<int>();

            for (int i = 0; i < row; i++)
            {
                for (int j = 0; j < col; j++)
                {
                    list.Add(matrix[i, j]);
                }
            }

            list = list.OrderBy(x => x).ToList();
            return list[k - 1];
    }
}

https://leetcode.com/problems/kth-smallest-element-in-a-sorted-matrix/#/description

leetcode378