File tree Expand file tree Collapse file tree 2 files changed +22
-23
lines changed
Expand file tree Collapse file tree 2 files changed +22
-23
lines changed Original file line number Diff line number Diff line change 44
55### 성능 요약
66
7- 메모리: 131 MB, 시간: 244.15 ms
7+ 메모리: 123 MB, 시간: 190.55 ms
88
99### 구분
1010
1616
1717### 제출 일자
1818
19- 2025년 08월 04일 10:09:21
19+ 2025년 09월 02일 18:20:18
2020
2121### 문제 설명
2222
Original file line number Diff line number Diff line change 22
33class Solution {
44 public String solution (int [] numbers ) {
5- // 문자열 배열로 변환
6- String [] numbersString = Arrays .stream (numbers )
7- .mapToObj (String ::valueOf )
8- .toArray (String []::new );
9-
10- // 정렬
11- Arrays .sort (numbersString , new Comparator <String >() {
12- @ Override
13- public int compare (String o1 , String o2 ) {
14- // 내림차순 정렬
15- return (o2 +o1 ).compareTo (o1 +o2 );
16- }
17- }
18- );
5+ // 사전 순 정렬
6+ ArrayList <String > strList = new ArrayList <>();
7+ for (int number : numbers ){
8+ strList .add (String .valueOf (number ));
9+ }
10+ Collections .sort (strList ,new Comparator <String >(){
11+ @ Override
12+ public int compare (String s1 , String s2 ){
13+ int num1 = Integer .parseInt (s1 +s2 );
14+ int num2 = Integer .parseInt (s2 +s1 );
15+
16+ return num2 - num1 ;
17+ }
18+
19+ });
1920
20- if (numbersString [0 ].equals ("0" )) return "0" ;
21-
22-
23- StringBuilder result = new StringBuilder ();
24- for (String number : numbersString ) {
25- result .append (number );
21+ StringBuilder stringBuilder = new StringBuilder ();
22+ for (String str : strList ){
23+ stringBuilder .append (str );
2624 }
27- return result .toString ();
25+ if (stringBuilder .toString ().startsWith ("0" )) return "0" ;
26+ return stringBuilder .toString ();
2827 }
2928}
You can’t perform that action at this time.
0 commit comments