JAVA_LeetCode 1337_The K Weakest Rows in a Matrix


JAVA_LeetCode 1337_The K Weakest Rows in a Matrix

JAVA_LeetCode 1337_The K Weakest Rows in a Matrix 풀이 class Solution { public int[] kWeakestRows(int[][] mat, int k) { int res[] = new int[k], arr[] = new int[mat.length]; int num = 0, min = 0; // 행 -> 열만큼 반복해서 1을 확인 for(int i = 0; i < mat.length; i++){ num = 0; for(int j = 0; j < mat[i].length; j++){ if(mat[i][j] == 1) num++; } arr[i] = num; } // k만큼 반복하며 행렬 최대값(200)과 비교하여 작은값을 체크하여 요소로 넣어준다. for(int i = 0; i < k; i++){ min = 0; for(int j = 0; j < mat.length; j++){ if(arr[j] < arr[min]) min = j;...


#JAVA #JAVA_LeetCode1337 #JAVA_LeetCode1337_TheKWeakestRowsinaMatrix #JAVA_TheKWeakestRowsinaMatrix #LeetCode1337_TheKWeakestRowsinaMatrix

원문링크 : JAVA_LeetCode 1337_The K Weakest Rows in a Matrix