Notice
Recent Posts
Recent Comments
Link
250x250
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- django
- C++
- 코딩테스트
- 백준
- DFS와BFS
- DART
- BAEKJOON
- vuejs
- 안드로이드
- Flutter
- AndroidStudio
- 알고리즘
- 코드품앗이
- android
- Algorithm
- DFS
- 동적계획법과최단거리역추적
- 개발
- 안드로이드스튜디오
- 코테
- 분할정복
- cos
- Python
- cos pro 1급
- issue
- 파이썬
- Vue
- 동적계획법
- cos pro
- codingtest
Archives
- Today
- Total
Development Artist
[COS Pro 1급, Python] 2차 8번 : 규칙에 맞는 배열 구하기 본문
728x90
반응형
문제 유형
한줄 수정
난이도
easy
Note
1. 배열 양끝에서 하나씩 번갈아가면서 원소 선택하는 알고리즘.
Code
# -*- coding: utf-8 -*-
# UTF-8 encoding when using korean
# 2차 8번
def solution(arr):
left, right = 0, len(arr) - 1
idx = 0
answer = [0 for _ in range(len(arr))]
while left <= right:
if idx % 2 == 0:
answer[idx] = arr[left]
left += 1
else:
answer[idx] = arr[right]
right -= 1
idx += 1
return answer
arr = [1, 2, 3, 4, 5, 6]
ret = solution(arr)
print("solution 함수의 반환 값은", ret, "입니다.")
※ 가끔 코드 중 print(~)가 있습니다. 정리 못한 점 죄송합니다.
728x90
반응형
'Algorithm > COS' 카테고리의 다른 글
[COS Pro 1급, Python] 2차 10번 : 0들을 0으로 만들기 (0) | 2022.02.25 |
---|---|
[COS Pro 1급, Python] 2차 9번 : 비밀번호 검사 (0) | 2022.02.25 |
[COS Pro 1급, Python] 2차 7번 : 거스름돈 구하기 (0) | 2022.02.25 |
[COS Pro 1급, Python] 2차 6번 : 로봇을 움직여주세요 (0) | 2022.02.25 |
[COS Pro 1급, Python] 2차 5번 : 언제까지 오르막길이야..?! (0) | 2022.02.25 |
Comments