728x90
SMALL

using System;
using System.Collections.Generic;

public class Solution {
    public int[] solution(string my_string) { 
        List<int> List = new List<int>();
        
        for(int i = 0; i < my_string.Length; i++)
        {  
            if(Char.IsDigit(my_string[i]) == true)
            {
                List.Add((int)my_string[i] - 48);
            }
        }
        
        int[] answer = List.ToArray();
        Array.Sort(answer);
        return answer;
    }
}

 

///

 

using System;
using System.Collections.Generic;
using System.Linq;

public class Solution {
    public int[] solution(string my_string) { 

        int[] answer = my_string.Where(x => char.IsNumber(x)).Select(x => Convert.ToInt32(x.ToString())).OrderBy(x => x).ToArray();

        Array.Sort(answer);
        return answer;
    }
}

 

파이썬

 

def solution(my_string):
    answer = []
    for i in my_string:
        if i.isdigit():
            answer.append(int(i))
    answer.sort()
    return answer

////

 

def solution(my_string):
    return sorted([int(c) for c in my_string if c.isdigit()])

 

//////

자바

//////

import java.util.*;

class Solution {
    public int[] solution(String my_string) {
        my_string = my_string.replaceAll("[a-z]","");
        int[] answer = new int[my_string.length()];

        for(int i =0; i<my_string.length(); i++)
        {
            answer[i] = my_string.charAt(i) - '0';
        }

        Arrays.sort(answer);

        return answer;
    }
}

 

 

import java.util.*;

class Solution {
    public int[] solution(String myString) {
        return Arrays.stream(myString.replaceAll("[A-Z|a-z]", "").split("")).sorted().mapToInt(Integer::parseInt).toArray();
    }
}
728x90

설정

트랙백

댓글