쉽고 깔끔하게
[프로그래머스/python3] Level 1 정수 내림차순으로 배치하기 문제풀이 본문
728x90
반응형

문제
programmers.co.kr/learn/courses/30/lessons/12933
코딩테스트 연습 - 정수 내림차순으로 배치하기
함수 solution은 정수 n을 매개변수로 입력받습니다. n의 각 자릿수를 큰것부터 작은 순으로 정렬한 새로운 정수를 리턴해주세요. 예를들어 n이 118372면 873211을 리턴하면 됩니다. 제한 조건 n은 1이
programmers.co.kr
함수 solution은 정수 n을 매개변수로 입력받습니다. n의 각 자릿수를 큰것부터 작은 순으로 정렬한 새로운 정수를 리턴해주세요.
<정답>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def solution(n): | |
result = sorted(str(n), reverse = True) | |
return int(''.join(result)) |
※ 그냥 ''.join(result)만 해주게 되면 "873211"이 문자로 출력되기 때문에 int로 한번 감싸줬다.
728x90
반응형
'Algorithm > Programmers' 카테고리의 다른 글
[프로그래머스 코딩 테스트 연습 SQL/MySQL] JOIN #2 있었는데요 없었습니다 문제풀이 (0) | 2021.01.20 |
---|---|
[프로그래머스 코딩 테스트 연습 SQL/MySQL] JOIN #1 없어진 기록 찾기 문제풀이 (0) | 2021.01.19 |
[프로그래머스/python3] Level 1 자릿수 더하기 문제풀이 (0) | 2021.01.19 |
[프로그래머스/python3] Level 1 문자열 다루기 기본 문제풀이 (0) | 2021.01.19 |
[프로그래머스/python3] Level 1 약수의 합 문제풀이 (0) | 2021.01.18 |