YJ의 새벽
프로그래머스(0) - 가장 큰 수 찾기 본문
class Solution {
public int[] solution(int[] array) {
int[] answer = new int[2]; // 2 개 만 추출.
int[] answer2 = array.clone();
Arrays.sort(array);
int maxValue = array[array.length-1]; // 최대값 추출
answer[0] = maxValue;
int index = 0;
for(int i=0; i<answer2.length; i++) {
if(answer2[i] == maxValue) { // 최대값 자리 추출
index = i;
break;
}
}
answer[1] = index;
return answer;
}
}
'코딩테스트연습 > 프로그래머스' 카테고리의 다른 글
프로그래머스(0) - 최댓값 만들기(2) [JAVA] (0) | 2024.03.13 |
---|---|
프로그래머스(0) - 직각삼각형 출력하기 (0) | 2024.03.13 |
프로그래머스(0) - 암호 해독 (0) | 2024.03.13 |
프로그래머스(0) - 대문자와 소문자 (0) | 2024.03.13 |
프로그래머스(0) - 가위 바위 보 (0) | 2024.03.13 |
Comments