728x90
SMALL

using System;
using System.Linq;

public class Solution {
    public int[] solution(int[] array) {
        int[] answer = new int[2] {array.Max(), Array.IndexOf(array, array.Max())};
        return answer;
    }
}

        //array.Max()는 배열 원소중 가장 큰수를 반환. Array.IndexOf는 지정한 개체를 검색하여 같은 원소가 있으면 그 인덱스 번호를 반환함

 

파이썬

 

def solution(array):
    val = max(array)
    return [val, array.index(val)]

 

자바

 

class Solution {
    public int[] solution(int[] array) {
        int[] answer = new int[2];

        for(int i=0;i<array.length;i++) 
        {
            if(array[i] > answer[0]) 
            {
                answer[0] = array[i];
                answer[1] = i;
            }
        }

        return answer;
    }
}

 

 

class Solution {
    public int[] solution(int[] array) {
        int max = 0;
        int maxIndex = -1;
        
        for (int i = 0; i < array.length; i++) 
        {
            if (max < array[i]) 
            {
                max = array[i];
                maxIndex = i;
            }
        }
        
        int[] answer = {max, maxIndex};
        return answer;
    }
}
728x90

설정

트랙백

댓글