코딩테스트/프로그래머스[Python]

[크레인 인형뽑기 게임]-[2019 카카오 개발자 겨울 인턴십] My answer def solution(board, moves): answer,cnt = 0, 0 tmp=[[0 for i in board] for j in board] array2=[0]*(len(board)**2) for i in range(len(board)): for j in range(len(board)): tmp[i][j]=board[j][i] for i in moves: for j in range(len(tmp[0])): if(tmp[i-1][j]!=0): array2[cnt]=tmp[i-1][j] tmp[i-1][j]=0 # 두개씩 만들어지면 터뜨리는 과정 if(cnt!=0 and array2[cnt-1]==array2[cn..
[K번째 수] My answer def solution(array, commands): tmp,answer = [],[] for i in commands: tmp=array[i[0]-1:i[1]] tmp.sort() answer.append(tmp[i[2]-1]) tmp=[] return answer Another answer def solution(array, commands): return [sorted(array[a[0]-1:a[1]])[a[2]-1] for a in commands] -------------------------------------------------------------------- def solution(array, commands): return list(map(lambd..
[폰켓몬]-[찾아라 프로그래밍 마스터] My answer def solution(nums): tmp=set(nums) if(len(nums)/2>=len(tmp)): return len(tmp) else: return len(nums)//2 Another answer def solution(nums): return min(len(set(nums)), len(nums)//2) [체육복]-[탐욕법(Greedy)] My answer def solution(n, lost, reserve): answer = 0 cloth = [1]*n for i in lost: cloth[i-1]-=1 for i in reserve: cloth[i-1]+=1 i=0 while(i!=len(cloth)): if(cloth[i]>1..
[복서 정렬하기]-[6주차 위클리 챌린지] My answer def solution(weights, head2head): wins, con1, tmp2 = [], [], [] tmp=0 for i in range(len(head2head)): # (승률= 이긴경기 / 전체경기)을 저장 if('W' in head2head[i])or('L' in head2head[i]): wins.append(head2head[i].count('W')/(len(head2head)-head2head[i].count('N'))) else: wins.append(0.0) # 자기보다 몸무게 높은사람한테 이긴횟수를 저장 for j in range(len(weights)): if(weights[j]>weights[i] and hea..
[부족한 금액 계산하기]-[1주차 위클리 테스트] My answer def solution(price, money, count): sum=0 for i in range(count): sum+=price*(i+1) if(money=90): answer+='A' elif(avg[i]>=80): answer+='B' elif(avg[i]>=70): answer+='C' elif(avg[i]>=50): answer+='D' else: answer+='F' return answer Another answer def solution(scores) : avgs=[] score=[ [i[j] for i in scores] for j in range(len(scores))] # 위의 list comprehension을 ..
[다트게임]-[2018 KAKAO BLIND RECRUITMENT] My answer def solution(dartResult): answer,flag = 0, 0 tmp, tmp2=[], [0]*12 score=0 # 여기부터 우선 다트결과를 각 회차별로 끊어놓은 거임 # 1번 방법 for i in range(len(dartResult)): # 옵션이 있을수도 없을수도 있기때문에 있을때만 앞의 tmp에 추가 if(dartResult[i]=='*' or dartResult[i]=='#'): tmp[-1]=tmp[-1]+dartResult[i] flag+=1 # 문자일때 끊기ㅂㅁ elif(dartResult[i].isdigit()==False): tmp.append(dartResult[flag:i+1])..
창빵맨
'코딩테스트/프로그래머스[Python]' 카테고리의 글 목록 (2 Page)