short and easy to understand c++ solution


  • 0
    I
        int kthSmallest(vector<vector<int>>& matrix, int k) {
            
            vector<int> all;
            for(int i=0; i < matrix.size(); i++)
                for(int j=0; j < matrix[0].size(); j++)
                    all.push_back(matrix[i][j]);
                
            sort(all.begin(), all.end());
            return all[k-1];
        }
    

    };


Log in to reply
 

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