There is a class with m students and n exams. You are given a 0-indexed m x n integer matrix score, where each row represents one student and score[i][j] denotes the score the ith student got in the jth exam. The matrix score contains distinct integers only.
You are also given an integer k. Sort the students (i.e., the rows of the matrix) by their scores in the kth (0-indexed) exam from the highest to the lowest.
Return the matrix after sorting it.
題目說做一個 m(學生數)*n(考試數) 的矩陣,裡面存放的每個數字都是唯一不重複的。題目還會給一個整數K,要求根據第k次考試(k是從0開始數)成績從高到低對學生進行排序並返回矩陣。
我的解題思路:
class Solution {
public int[][] sortTheStudents(int[][] score, int k) {
int m = score.length;
for (int i = 0; i < m-1 ; i++) {
for (int j = 0; j < m-1 - i; j++) {
// 比較第j行和第j+1行的第k列
if (score[j][k] < score[j + 1][k]) {
// 交換整行數據
int[] temp = score[j];
score[j] = score[j + 1];
score[j + 1] = temp;
}
}
}
return score;
}
}
普通的完成了
話說難度的依據到底是啥啊?
我覺得前幾天寫的那個石頭遊戲跟這題根本不同維度,明明都是中等題,這差距也太大!!