https://school.programmers.co.kr/learn/courses/30/lessons/120899#
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
function solution(array)
{
var max = Math.max(...array);
// 배열의 원소 중 최대를 추출
var index = array.indexOf(max);
// 원래 배열에 있던 최대값의 인덱스를 추출.
return [max, index];
}
+)230512
const solution = (array) => {
return [Math.max(...array), array.indexOf(Math.max(...array))];
}
230527 python
def solution(array):
return [max(array), array.index(max(array))]
230916 C++
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> solution(vector<int> array) {
int max = *max_element(array.begin(), array.end());
int index = find(array.begin(), array.end(), max) - array.begin();
return {max, index};
}
'코딩테스트 > LV. 0' 카테고리의 다른 글
LV. 0 :: A로 B 만들기 (0) | 2023.01.23 |
---|---|
LV. 0 :: 최댓값 만들기 2 (0) | 2023.01.23 |
LV. 0 :: 로그인 성공 (0) | 2023.01.23 |
LV. 0 :: 삼각형의 완성조건 2 (0) | 2023.01.23 |
LV. 0 :: 공 던지기 (0) | 2023.01.23 |
댓글