정수 배열 arr가 주어집니다. 이때 arr의 원소는 1 또는 0입니다. 정수 idx가 주어졌을 때, idx보다 크면서 배열의 값이 1인 가장 작은 인덱스를 찾아서 반환하는 solution 함수를 완성해 주세요.
단, 만약 그러한 인덱스가 없다면 -1을 반환합니다.
code - 1차
def solution(arr, idx):
answer = ''
for i in arr:
answer += str(i)
return (answer.find("1", idx))
code - 2차
def solution(arr, idx):
# 찾을 문자, 시작지점, 종료지점
try:
return arr.index(1, idx)
except ValueError:
return -1
https://github.com/seonmin5/codingtest_Python
GitHub - seonmin5/codingtest_Python
Contribute to seonmin5/codingtest_Python development by creating an account on GitHub.
github.com
반응형