코딩테스트

[로또의 최고 순위와 최저 순위]-[2021 Dev-Matching: 웹 백엔드 개발자] My answer def solution(lottos, win_nums): count=0 rank={6:1,5:2,4:3,3:4,2:5,1:6,0:6} for i in lottos: if(i in win_nums): count+=1 answer=[rank[count+lottos.count(0)],rank[count]] return answer Another answer def solution(lottos, win_nums): rank = {0: 6,1: 6,2: 5,3: 4,4: 3,5: 2,6: 1} return [rank[len(set(lottos) & set(win_nums)) + lottos.count(0)]..
[숫자 문자열과 영단어]-[2021 카카오 채용연계형 인턴십] My answer def solution(s): code=["zero","one","two","three","four","five","six","seven","eight","nine"] answer,tmp = "", "" for i in range(len(s)): if(s[i].isdigit()): answer+=s[i] else: tmp+=s[i] if(tmp!="" and tmp in code): for i in range(len(code)): if(tmp==code[i]): answer+=str(i) tmp="" return int(answer) Another answer num_dic = {"zero":"0", "one":"1", "t..
[크레인 인형뽑기 게임]-[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..
창빵맨
'코딩테스트' 카테고리의 글 목록 (35 Page)