슈콩

[프로그래머스] 문자열 정렬하기(1) 본문

Algorithms/Programmers

[프로그래머스] 문자열 정렬하기(1)

shukong 2025. 10. 12. 13:09

 

[소스 코드]

import java.util.*;
class Solution {
    public int[] solution(String my_string) {
        List<Integer> list = new ArrayList<>();
        int n = my_string.length();
        for(int i=0;i<n;i++){
            if(my_string.charAt(i)>='0' && my_string.charAt(i)<='9'){
                 list.add(my_string.charAt(i)-'0');
            }
        }
        Collections.sort(list);
        int[] answer = new int[list.size()];
        int idx = 0;
        for(int i : list){
            answer[idx++] = i;
        }
        return answer;
    }
}