프로그래머스
프로그래머스 Lv2 (최대값, 최소값 구하기)
JeonInwoo
2020. 2. 4. 14:32
풀이 방법
split(" ") 으로 자른 후 비교해서 min, max를 판별한다.
내 코드
class Solution {
public String solution(String s) {
String answer = "";
String str[] = s.split(" ");
int min, max, temp;
min = max = Integer.parseInt(str[0]);
for(int i=1; i<str.length; i++) {
temp = Integer.parseInt(str[i]);
if(temp > max) max = temp;
else if(temp < min) min = temp;
}
return min + " " + max;
}
}