Computer Science/자료구조

[6.5] 프로그래머스 코딩테스트 연습 - 두개 뽑아서 더하기(1/100)

토마토. 2021. 6. 5. 14:49

def solution(numbers):
  answer = []
  n = len(numbers)
  if 2 <= n <= 100:
    for i in range(n):
      for j in range(i+1, n):
        if (numbers[i]+numbers[j]) not in answer:
          if 0 <= numbers[i] <= 100 and 0 <= numbers[j] <= 100:
            answer.append(numbers[i]+numbers[j])
          else:
            pass
  else:
    print('error')
  answer.sort()
  return answer
print(solution([5, 7, 8, 10, 2, 6]))