[Python / 프로그래머스 level 2] 카펫 def solution(brown, yellow): s = brown + yellow for longth in range(s,2,-1): if s % longth == 0: length = s // longth if yellow == (longth - 2) * (length - 2): return [longth, length] Language/Python 2021.08.10
[Python / 프로그래머스 level 2] 주식가격 from collections import deque def solution(prices): queue = deque(prices) answer = [] while queue: price = queue.popleft() sec = 0 for q in queue: sec += 1 if price > q: break answer.append(sec) return answer Language/Python 2021.08.09
[Python / 프로그래머스 level 2] 행렬의 곱셈 import numpy as np def solution(A, B): answer = [[]] answer = (np.matrix(A)*np.matrix(B)).tolist() return answer Language/Python 2021.08.05
[Python / 프로그래머스 level 2] H-Index def solution(citations): citations.sort() l = len(citations) for i in range(l): if citations[i] >= l-i: return l-i return 0 Language/Python 2021.08.04
[Python / 프로그래머스 level 2] 최솟값 만들기 def solution(A,B): answer = 0 A.sort(reverse = True) B.sort() for i in range(len(A)): answer += (A[i]*B[i]) return answer Language/Python 2021.08.03
[Python / 프로그래머스 level 2] 가장 큰 수 def solution(numbers): numbers = list(map(str, numbers)) numbers.sort(key=lambda x: x*3, reverse = True) return str(int(''.join(numbers))) Language/Python 2021.08.02
[Python / 프로그래머스 level 2] N개의 최소공배수 def solution(arr): from math import gcd answer = arr[0] for i in arr: answer = answer * i // gcd(answer,i) return answer Language/Python 2021.07.30
[Python / 프로그래머스 level 2] 숫자의 표현 def solution(n): answer = 0 for i in range(1, n+1): sum = 0 for j in range(i, n+1): sum += j if sum == n: answer += 1 break elif sum > n: break return answer Language/Python 2021.07.28
[Python / 프로그래머스 level 2] 최댓값과 최솟값 def solution(s): answer = '' s = list(map(int, s.split(' '))) mi = min(s) ma = max(s) answer = str(mi) + " " + str(ma) return answer Language/Python 2021.07.27
[Python / 프로그래머스 level 1] 서울에서 김서방 찾기 def solution(seoul): i = 0 for i in range(len(seoul)): if seoul[i] == 'Kim': i += 1 return '김서방은 ' + str(i-1) + '에 있다' Language/Python 2021.07.26