본문 바로가기

join53

Write Number in Expanded Form 문제 설명 You will be given a number and you will need to return it as a string in Expanded Form. For example: expanded_form(12) # Should return '10 + 2' expanded_form(42) # Should return '40 + 2' expanded_form(70304) # Should return '70000 + 300 + 4' NOTE: All numbers will be whole numbers greater than 0. 해결 방법 1. 숫자를 문자열로 바꾼다. 2. 문자열 중에 '0'이 아닌 수를 찾는다. 3. 찾은 수에 현재 남은 자리수 만큼 '0'을 붙인다. 4. 리스트에 담는다. .. 2022. 2. 18.
Stop gninnipS My sdroW! 문제 설명 Write a function that takes in a string of one or more words, and returns the same string, but with all five or more letter words reversed (Just like the name of this Kata). Strings passed in will consist of only letters and spaces. Spaces will be included only when more than one word is present. Examples: spinWords( "Hey fellow warriors" ) => returns "Hey wollef sroirraw" spinWords( "This.. 2022. 2. 15.
Ones and Zeros 문제 설명 Given an array of ones and zeroes, convert the equivalent binary value to an integer. Eg: [0, 0, 0, 1] is treated as 0001 which is the binary representation of 1. Examples: Testing: [0, 0, 0, 1] ==> 1 Testing: [0, 0, 1, 0] ==> 2 Testing: [0, 1, 0, 1] ==> 5 Testing: [1, 0, 0, 1] ==> 9 Testing: [0, 0, 1, 0] ==> 2 Testing: [0, 1, 1, 0] ==> 6 Testing: [1, 1, 1, 1] ==> 15 Testing: [1, 0, 1, 1] .. 2022. 2. 12.
문자열 내림차순으로 배치하기 문제 설명 문자열 s에 나타나는 문자를 큰것부터 작은 순으로 정렬해 새로운 문자열을 리턴하는 함수, solution을 완성해주세요. s는 영문 대소문자로만 구성되어 있으며, 대문자는 소문자보다 작은 것으로 간주합니다. 제한 사항 str은 길이 1 이상인 문자열입니다. 해결 방법 1. 문자열을 내림차순으로 정렬하여 반환한다. def solution(s): answer = ''.join(sorted(s, reverse=True)) return answer sorted 와 reverse 속성, 그리고 join을 활용하면 쉽게 풀 수 있다. 여기서 join은 sorted로 인해 리스트로 변형된 문자열을 다시 합쳐준다. 출처: 프로그래머스 코딩 테스트 연습, https://programmers.co.kr/lear.. 2022. 2. 1.
정수 내림차순으로 배치하기 문제 설명 함수 solution은 정수 n을 매개변수로 입력받습니다. n의 각 자릿수를 큰것부터 작은 순으로 정렬한 새로운 정수를 리턴해주세요. 예를들어 n이 118372면 873211을 리턴하면 됩니다. 제한 조건 n은 1이상 8000000000 이하인 자연수입니다. 해결 방법 1. n을 이터러블한 str로 바꾼다 2. 내림차순이므로 역순으로 정렬한다 3. 정렬과정에서 리스트로 변경된 값을 다시 문자열로 바꾸어준다 4. 최종 값을 반환하기 위해 문자열을 숫자로 바꾸어 준다. def solution(n): return int(''.join(sorted(str(n), reverse=True))) 2022. 1. 23.