Skip to content

Commit

Permalink
자연수 내림차순 정렬하기
Browse files Browse the repository at this point in the history
  • Loading branch information
sey2 authored Aug 15, 2022
1 parent da1da6c commit d297677
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions programmers/IntRevers.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import java.util.*;

class Solution {
public long solution(long n) {
String str = Long.toString(n);
PriorityQueue<String> pq = new PriorityQueue<>(Collections.reverseOrder());

for(int i=0; i<str.length(); i++) pq.add(Integer.toString(str.charAt(i)-48));

String ans ="";
while(!pq.isEmpty()) ans+= pq.poll();

return Long.parseLong(ans);
}
}

0 comments on commit d297677

Please sign in to comment.