Skip to content

Commit

Permalink
프로그래머스/Sort: 가장 큰 수 (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
sieunnnn committed Dec 19, 2023
1 parent a5c70ef commit 466c50b
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/programmers/algorithmKit/sort/PROB02.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package programmers.algorithmKit.sort;

import java.util.*;

public class PROB02 {
public String solution(int[] numbers) {
String[] strNumbers = new String[numbers.length];

for (int i = 0; i < numbers.length; i++) {
strNumbers[i] = String.valueOf(numbers[i]);
}

Arrays.sort(strNumbers, (o1, o2) -> (o2 + o1).compareTo(o1 + o2));

// 모든 숫자가 0일 경우 "0"을 반환
if (strNumbers[0].equals("0")) {
return "0";
}

return String.join("", strNumbers);
}
}

0 comments on commit 466c50b

Please sign in to comment.