-
두 정수 사이의 합프로그래밍/알고리즘 2021. 3. 28. 16:58
나의 풀이
def solution(a, b): return sum(range(min(a, b), max(a, b)+1))
for문에 자주 쓰이는 range를 사용했다.
주어진 두 수를 작은 수와 큰 수로 구분한 뒤 범위 값으로 지정해 (range이기 때문에 뒤에는 +1을 해주었다.)
넘어오는 수를 차례대로 sum함수를 사용해서 풀었다.
728x90반응형LIST'프로그래밍 > 알고리즘' 카테고리의 다른 글
124 나라의 숫자 (0) 2021.03.30 프린터 (0) 2021.03.30 크레인 인형뽑기 게임 (0) 2021.03.28 행렬의 덧셈 (0) 2021.03.28 평균 구하기 (0) 2021.03.27