Java solution 18ms


  • 0
    U

    public class Solution {

    public int kthSmallest(int[][] matrix, int k) {
        int i = 0;
        int[] list = new int[(matrix.length) * (matrix.length)]; 
        while(i< matrix.length){
            int j = 0;
            while(j< matrix.length){
    
                list[((i) * matrix.length)+j] = matrix[i][j];
                j++;
            }
            i++;
        }
        Arrays.sort(list);
    
        return list[k-1];
    }
    

    }


  • 0

    @ushockey
    I do not think this is the solution your interviewer would like to see. It is literally a kind of brute force.


Log in to reply
 

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