Deep_Dev
article thumbnail

 

 


Level 2์—์„œ ์•„๋งˆ ์ œ์ผ ์‰ฌ์šด๋ฌธ์ œ์ผ ๊ฒƒ์ด๋‹ค.

 

 

< ๋‚ด ํ’€์ด >

import java.util.*;
class Solution {
    public String solution(String s) {
        String answer = "";

        String[] str=s.split(" ");

        ArrayList<Integer> list = new ArrayList<>();

        for(int i=0; i<str.length; i++){
            list.add(Integer.parseInt(str[i]));
        }
        Collections.sort(list);
        int min = list.get(0);
        int max = list.get(list.size()-1);
        answer=min+" "+max;
        return answer;
    }
}

 

 

 

< ๋” ์ข‹์€ ๋‹ค๋ฅธ๋ถ„ ์ฝ”๋“œ >

import java.util.*;
class Solution {
    public String solution(String s) {
        tring[] tmp = str.split(" ");
        int min, max, n;
        min = max = Integer.parseInt(tmp[0]);
        for (int i = 1; i < tmp.length; i++) {
            n = Integer.parseInt(tmp[i]);
            if(min > n) min = n;
            if(max < n) max = n;
        }
        return min + " " + max;
    }
}