공부/코딩테스트 51

[프로그래머스] 행렬의 곱셈(파이썬)

나의 답 : def solution(arr1, arr2): #arr1 * arr2가 안 되고, #arr2 * arr1가 될 수도 있기 때문에 확인 후 바꾼다. if len(arr1[0]) != len(arr2): arr1,arr2 = arr2, arr1 x=len(arr1) y=len(arr2) z=len(arr2[0]) # x*y 행렬과 y*z 행렬의 곱 => x*z 행렬 #x*z의 빈 행렬 만들기 answer = [] for i in range(x): temp=[] for j in range(z): temp.append(0) answer.append(temp) #값 넣기 for i in range(x): for j in range(y): for k in range(z): answer[i][k]+=ar..

[프로그래머스] 로또의 최고 순위와 최저 순위(파이썬)

나의 답 : def solution(lottos, win_nums): minlotto=7 maxlotto=6 for i in lottos: if i in win_nums: minlotto-=1 maxlotto=minlotto-lottos.count(0) if minlotto==7: minlotto=6 if maxlotto==7: maxlotto=6 return [maxlotto,minlotto] 다른 사람의 답 : def solution(lottos, win_nums): rank=[6,6,5,4,3,2,1] cnt_0 = lottos.count(0) ans = 0 for x in win_nums: if x in lottos: ans += 1 return rank[cnt_0 + ans],rank[ans]