Notice
Recent Posts
Recent Comments
Today
Total
01-10 22:06
Link
๊ด€๋ฆฌ ๋ฉ”๋‰ด

Partially Committed

[์ •๋ ฌ] ๊ฐ€์žฅ ํฐ ์ˆ˜ (JAVA) ๋ณธ๋ฌธ

๐Ÿ”ฅ Algorithm || ๋ฌธ์ œํ’€์ด/PS

[์ •๋ ฌ] ๊ฐ€์žฅ ํฐ ์ˆ˜ (JAVA)

WonderJay 2022. 9. 2. 15:37
728x90
๋ฐ˜์‘ํ˜•
SMALL

https://school.programmers.co.kr/learn/courses/30/lessons/42746?language=java 

 

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”.

programmers.co.kr

import java.io.IOException;
import java.util.Arrays;
import java.util.Comparator;

class Solution {
    public String solution(int[] numbers) throws IOException {
        StringBuilder answer = new StringBuilder();
        String[] result = new String[numbers.length];
        for(int i = 0 ; i < numbers.length; i++)
            result[i] = String.valueOf(numbers[i]);

        Arrays.sort(result, new Comparator<String>(){
            @Override
            public int compare(String o1, String o2){
                return (o2+o1).compareTo(o1+o2);
            }
        });
        
        for(String e : result)
            answer.append(e);
        if(answer.charAt(0) == '0') return "0";
        return answer.toString();
    }
}
728x90
๋ฐ˜์‘ํ˜•
LIST
Comments