Deep_Dev
article thumbnail

๋ฌธ์ œ ์„ค๋ช…

๋ฌธ์ž์—ด my_string์ด ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, my_string ์•ˆ์— ์žˆ๋Š” ์ˆซ์ž๋งŒ ๊ณจ๋ผ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌํ•œ ๋ฆฌ์ŠคํŠธ๋ฅผ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑํ•ด๋ณด์„ธ์š”.

 
์ œํ•œ์‚ฌํ•ญ
  • 1 ≤ my_string์˜ ๊ธธ์ด ≤ 100
  • my_string์—๋Š” ์ˆซ์ž๊ฐ€ ํ•œ ๊ฐœ ์ด์ƒ ํฌํ•จ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.
  • my_string์€ ์˜์–ด ์†Œ๋ฌธ์ž ๋˜๋Š” 0๋ถ€ํ„ฐ 9๊นŒ์ง€์˜ ์ˆซ์ž๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์Šต๋‹ˆ๋‹ค. - - -

 

์ž…์ถœ๋ ฅ ์˜ˆ
"hi12392" [1, 2, 2, 3, 9]
"p2o4i8gj2" [2, 2, 4, 8]
"abcde0" [0]

 

 


replaceAll... ([^0-9]...

split ๋ฉ”์†Œ๋“œ๋กœ ๋ฐฐ์—ด์— ๋‹ด์•„์ฃผ๊ณ ..

๋ฌธ์ž์—ด -> ์ •์ˆ˜๋Š” Integer.parseInt .. ! 


import java.util.Arrays;
import java.util.Scanner;
class Solution {
    public int[] solution(String my_string) {
            String result=my_string.replaceAll("[^0-9]","");
            String[] arr=result.split("");
            int[] answer=new int[arr.length];
            for(int i=0; i<arr.length; i++){
                answer[i]=Integer.parseInt(arr[i]);
            }
            Arrays.sort(answer);
            return answer;
    }
}