Skip to content

Commit 511633d

Browse files
committed
feat : 프로그래머스 정렬
1 parent 3f0d4c1 commit 511633d

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package sgyj.programmers.yeji.sort;
2+
3+
import java.util.Arrays;
4+
import java.util.stream.Collectors;
5+
6+
public class Solution42746 {
7+
public static String solution(int[] numbers) {
8+
String answer = Arrays.stream( numbers ).mapToObj( Integer::toString ).sorted( ( o1, o2 ) -> ( o2 + o1).compareTo( o1 + o2 ) ).collect( Collectors.joining());
9+
return answer.startsWith("0") ? String.valueOf(Integer.parseInt(answer)) : answer;
10+
}
11+
12+
public static void main ( String[] args ) {
13+
int[] numbers = {0,0,0,0,0};
14+
System.out.println(solution( numbers ));
15+
}
16+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package sgyj.programmers.yeji.sort;
2+
3+
import java.util.Arrays;
4+
5+
public class Solution42748 {
6+
7+
public static int[] solution(int[] array, int[][] commands) {
8+
int[] answer = new int[commands.length];
9+
10+
for(int c=0; c<commands.length; c++){
11+
int start = commands[c][0]-1;
12+
int end = commands[c][1];
13+
int target = commands[c][2]-1;
14+
15+
int[] arr = Arrays.copyOfRange( array, start, end);
16+
Arrays.sort(arr);
17+
answer[c] = arr[target];
18+
}
19+
20+
return answer;
21+
}
22+
23+
public static void main ( String[] args ) {
24+
int[] array = {1, 5, 2, 6, 3, 7, 4};
25+
int[][] commands = {
26+
{2,5,3},{4,4,1},{1,7,3}
27+
};
28+
29+
for(int s : solution(array,commands)){
30+
System.out.print(s +" ");
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)