Java maybe easiest to understand


  • 0
    T
    public class Solution 
    {
        public int kthSmallest(int[][] matrix, int k) 
        {
            int n = matrix.length;
            ArrayList<Integer> li = new ArrayList<Integer>();
            for(int i = 0; i < n; i++)
            {
                for(int j = 0; j < n; j++)
                {
                    li.add(matrix[i][j]);
                }
            }
            Collections.sort(li);
            return li.get(k-1);
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.