문제
코딩테스트 연습 - 두 개 뽑아서 더하기
정수 배열 numbers가 주어집니다. numbers에서 서로 다른 인덱스에 있는 두 개의 수를 뽑아 더해서 만들 수 있는 모든 수를 배열에 오름차순으로 담아 return 하도록 solution 함수를 완성해주세요. 제한
programmers.co.kr

풀이
import collections as coll
def solution(numbers):
answer = []
dic = coll.defaultdict(int)
numbers.sort()
ln = len(numbers)
for i in range(ln):
for j in range(ln):
if i==j: continue
x=numbers[i]+numbers[j]
if x not in dic:
dic[x]=0
answer = list(dic.keys())
answer.sort()
return answer

ㅋㅋ.. 3월에 코테를 왕창 볼 예정이어서 빡공해야 하는데
쉬운 문제만 골라 풀고있다 ㅠㅠㅠㅠ 흑흑 정신채리~~~
반응형
'Problem Solving > Programmers' 카테고리의 다른 글
| 프로그래머스 (Level 2) : 오픈채팅방 / Python, dictionary / 2019 KAKAO BLIND RECRUITMENT (0) | 2022.04.20 |
|---|---|
| SQL (Level 2) : 중성화 여부 파악하기 - ORACLE, CASE (0) | 2022.03.18 |
| 프로그래머스 (Level 1) : 실패율 / Python, dictionary, 커스텀 sorted(lambda) (0) | 2022.02.16 |
| 프로그래머스 (Level 1) : 없는 숫자 더하기 (Python, dictionary) (3) | 2022.02.13 |
| 프로그래머스 (Level 1) : 숫자 문자열과 영단어 (Python, dictionary) (2) | 2022.02.09 |