목록Algorithm/Programmers (76)
S E P H ' S
코딩테스트 연습 - 완주하지 못한 선수 수많은 마라톤 선수들이 마라톤에 참여하였습니다. 단 한 명의 선수를 제외하고는 모든 선수가 마라톤을 완주하였습니다. 마라톤에 참여한 선수들의 이름이 담긴 배열 participant와 완주한 선수 programmers.co.kr def solution(participant, completion): participant.sort() completion.sort() for p, c in zip(participant, completion): if p != c: return p return participant[-1]
코딩테스트 연습 - 크레인 인형뽑기 게임 [[0,0,0,0,0],[0,0,1,0,3],[0,2,5,0,1],[4,2,4,4,2],[3,5,1,3,1]] [1,5,3,5,1,2,1,4] 4 programmers.co.kr 문제 설명 게임개발자인 "죠르디"는 크레인 인형뽑기 기계를 모바일 게임으로 만들려고 합니다. "죠르디"는 게임의 재미를 높이기 위해 화면 구성과 규칙을 다음과 같이 게임 로직에 반영하려고 합니다. 게임 화면은 "1 x 1" 크기의 칸들로 이루어진 "N x N" 크기의 정사각 격자이며 위쪽에는 크레인이 있고 오른쪽에는 바구니가 있습니다. (위 그림은 "5 x 5" 크기의 예시입니다). 각 격자 칸에는 다양한 인형이 들어 있으며 인형이 없는 칸은 빈칸입니다. 모든 인형은 "1 x 1" 크기의..
출처 : https://programmers.co.kr/learn/courses/30/lessons/12934 코딩테스트 연습 - 정수 제곱근 판별 임의의 양의 정수 n에 대해, n이 어떤 양의 정수 x의 제곱인지 아닌지 판단하려 합니다. n이 양의 정수 x의 제곱이라면 x+1의 제곱을 리턴하고, n이 양의 정수 x의 제곱이 아니라면 -1을 리턴하는 함 programmers.co.kr 1. 제곱근과 제곱수를 구하기 위해 import math 2. n이 양의 정수 제곱근이면 n+1의 제곱을, 아니면 -1을 리턴 import math def sol(n): return pow(math.sqrt(n)+1, 2) if int(math.sqrt(n)) == math.sqrt(n) else -1
출처 : https://programmers.co.kr/learn/courses/30/lessons/12935# 코딩테스트 연습 - 제일 작은 수 제거하기 정수를 저장한 배열, arr 에서 가장 작은 수를 제거한 배열을 리턴하는 함수, solution을 완성해주세요. 단, 리턴하려는 배열이 빈 배열인 경우엔 배열에 -1을 채워 리턴하세요. 예를들어 arr이 [4,3,2,1 programmers.co.kr 1. 빈 배열인 경우를 먼저 체크. 2. 아니라면 배열에서 가장 작은 값의 인덱스를 사용하여 제거. 3. 반환 def solution(arr): if len(arr) > 1: arr.pop(arr.index(min(arr))) return arr else: return [-1]