[Programmers]-최댓값과 최솟값
문제
문자열에서 최댓값과 최소값을 반환하는문제이다.
코드
class Solution {
public String solution(String s) {
String[] list = s.split(" ");
int max = Integer.parseInt(list[0]);
int min = Integer.parseInt(list[0]);
for(String value : list){
if(min > Integer.parseInt(value)) min = Integer.parseInt(value);
if(max < Integer.parseInt(value)) max = Integer.parseInt(value);
}
return min+" "+max;
}
}
코드 설명
최대, 최소값을 초기화하고 비교로 구하면 된다.
요약
- 없다.