> For the complete documentation index, see [llms.txt](https://r24zeng.gitbook.io/leetcode-notebook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://r24zeng.gitbook.io/leetcode-notebook/bu-chong-6180-dao/378.-kth-smallest-element-in-a-sorted-matrix.md).

# 378. Kth Smallest Element in a Sorted Matrix

\# Medium

{% hint style="info" %}
Because we can't find the next step should go down or right  according to column and row ascending principle, the focus of this problem is not about the matrix, it is about sorting. In an ascending array, return `a[k-1]`.
{% endhint %}

```python
class Solution:
    def kthSmallest(self, matrix: List[List[int]], k: int) -> int:
        res = []
        for i in range(len(matrix)):
            for j in range(len(matrix[i])):
                res.append(matrix[i][j])
                
        res.sort()
        return res[k-1]
```
