가장 큰 수 찾기

han.user();·2023년 4월 1일
0

프로그래머스

목록 보기
19/87
post-thumbnail

class Solution {
    public int[] solution(int[] array) {
        int maxValue = -1;
        int maxIndex = -1;

        for (int i = 0; i < array.length; i++) {
            if (array[i] > maxValue) {
                maxValue = array[i];
                maxIndex = i;
            }
        }
        int[] result = new int[2];
        result[0] = maxValue;
        result[1] = maxIndex;

        return result;
    }
}
profile
I'm still hungry.

0개의 댓글