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;
}
}
'๐ ์ฝ๋ฉํ ์คํธ > ๋ฐฑ์ค & ํ๋ก๊ทธ๋๋จธ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค][JAVA] Level 2 : ์ต์๊ฐ ๋ง๋ค๊ธฐ (0) | 2023.03.27 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค][JAVA]Level 2 : JadenCase ๋ฌธ์์ด ๋ง๋ค๊ธฐ (0) | 2023.03.26 |
[ํ๋ก๊ทธ๋๋จธ์ค][JAVA]Level 1 : ์น์์ด (2) (0) | 2023.03.15 |
[ํ๋ก๊ทธ๋๋จธ์ค][JAVA]Level 1 : ๋๋ง์ ์ํธ (0) | 2023.03.14 |
[ํ๋ก๊ทธ๋๋จธ์ค][JAVA]Level 1 : [1์ฐจ]๋น๋ฐ์ง๋ (0) | 2023.03.14 |