티스토리 뷰
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | import java.util.*; class Solution { public int[][] solution(int[][] data, String ext, int val_ext, String sort_by) { List indexList = Arrays.asList("code","date","maximum","remain"); int extIdx = indexList.indexOf(ext); int sortIdx = indexList.indexOf(sort_by); // 수기로 오름차순 정렬하는 방법 List<int[]> answerList = new ArrayList<>(); for(int i = 0 ; i < data.length; i++){ if(data[i][extIdx] < val_ext ){ answerList.add(data[i]); } } int [] temp = {}; int listSize = answerList.size(); for(int j = 0 ; j < listSize ; j++){ for(int k = j+1 ; k < listSize; k++){ if(answerList.get(k)[sortIdx] < answerList.get(j)[sortIdx]){ temp = answerList.get(k); answerList.set(k, answerList.get(j) ); answerList.set(j, temp); } } } int [][] answer = answerList.toArray(int[][]::new); //스트림 필터를 이용해서 필터링 및 오름차순 정렬하는 방법 Arrays.stream(data).filter(d -> d[extIdx] > val_ext).sorted((d1, d2) -> d1[sortIdx] - d2[sortIdx]).toArray(int[][]::new); } } | cs |