Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 이코테
- SW
- Algorithm
- 항해플러스
- createSlice
- Get
- Python
- JavaScript
- programmers
- 프로그래머스
- react
- 항해99
- react-redux
- 코딩테스트합격자되기
- sw expert academy
- redux
- java
- json-server
- axios
- redux-saga
- 매일메일
- maeil-mail
- react-router
- C++
- 테코테코
- 리액트
- 알고리즘
- useDispatch
- 자바
- redux-toolkit
Archives
- Today
- Total
Binary Journey
[프로그래머스] 모의고사 본문
반응형
출처: 프로그래머스 코딩 테스트 연습, https://programmers.co.kr/learn/challenges
** Javascript
function solution(answers) {
let answer = [];
const first = [1, 2, 3, 4, 5];
const second = [2, 1, 2, 3, 2, 4, 2, 5];
const third = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5];
const supoja1 = answers.filter((answer, index) => answer === first[index % first.length]).length;
const supoja2 = answers.filter((answer, index) => answer === second[index % second.length]).length;
const supoja3 = answers.filter((answer, index) => answer === third[index % third.length]).length;
const max = Math.max(supoja1, supoja2, supoja3);
if (supoja1 === max) {
answer.push(1);
}
if (supoja2 === max) {
answer.push(2);
}
if (supoja3 === max) {
answer.push(3);
}
return answer;
}
** Python
def solution(answers):
arr1 = [1, 2, 3, 4, 5]
arr2 = [2, 1, 2, 3, 2, 4, 2, 5]
arr3 = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5]
s = [0, 0, 0]
for i, e in enumerate(answers):
if e == arr1[i % len(arr1)]: s[0] += 1
if e == arr2[i % len(arr2)]: s[1] += 1
if e == arr3[i % len(arr3)]: s[2] += 1
maxS = max(s)
answer = [i + 1 for i, e in enumerate(s) if e == maxS]
return answer
반응형
'프로그래머스 > level 1' 카테고리의 다른 글
[프로그래머스] 완주하지 못한 선수 (0) | 2021.11.01 |
---|---|
[프로그래머스] k번째 수 (0) | 2021.10.25 |
[프로그래머스] 나머지가 1이 되는 수 찾기 (0) | 2021.10.25 |
[프로그래머스] 폰켓몬 (0) | 2021.10.18 |
[프로그래머스] 체육복 (0) | 2021.10.18 |