Skip to content

Instantly share code, notes, and snippets.

@qkreltms
Last active June 3, 2018 00:25
Show Gist options
  • Select an option

  • Save qkreltms/24f38aa0070a2dca4d09c41c7e8c665c to your computer and use it in GitHub Desktop.

Select an option

Save qkreltms/24f38aa0070a2dca4d09c41c7e8c665c to your computer and use it in GitHub Desktop.
정수 배열이 주어질 때 0보다 크고 배열에 없는 가장 작은 양의 정수 찾기
def solution(arr):
# 음수는 제외(없어도 상관없음)
arr = list(filter(lambda item: item > 0, arr))
# start를 1부터 n까지 +1씩 하면서 배열에 없으면 start반환
start = 1
while True:
if start not in arr:
return start
start += 1
print(solution([-1,1,3]))
print(solution([-1,3,2]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment