기능 개발 (큐)
·
Coding Test/programmers
def solution(progresses, speeds): answer = [] cnt = 0 day = 0 while len(progresses)>0: if progresses[0] + day*speeds[0] >= 100: # 완료 progresses.pop(0) speeds.pop(0) cnt+=1 else: # 미완 if cnt>0: # 지금까지 완료한 기능 배포하고 초기화 answer.append(cnt) cnt=0 day+=1 answer.append(cnt) return answer
더 맵게 (힙)
·
Coding Test/programmers
from heapq import heapify, heappush, heappop def solution(scoville, K): cnt=0 heapify(scoville) while True: now=heappop(scoville) if now>=K: break if len(scoville)
주식 가격 (큐/스택)
·
Coding Test/programmers
스택 """ 1. answer의 값을 주식의 가격이 떨어지지 않았을 경우로 초기화한다. 2. rices를 순회하며 stack의 top의 인덱스보다 현재 price의 값이 작을 경우, pop후, answer값을 수정하는 것을 반복한다. """ def solution(prices): n = len(prices) answer = [i for i in range(n-1,-1,-1)] # 주식 가격이 떨어질 경우 찾기 stack = [0] for i in range(1, n): while stack and prices[stack[-1]] > prices[i]: # 스택 맨 위 j = stack.pop() answer[j]=i-j stack.append(i) return answer print(solution([1..
선입 선출 스케줄링 (이분 탐색)
·
Coding Test/programmers
def solution(n,cores): answer=0 if n = n: r=mid else: l=mid+1 #찾아낸 (r-1) 까지의 총 작업수를 n에서 뺌 n -= sum(map(lambda x: (r-1)//x, cores)) # 남아있는 작업 수는 전부 현재 시간(r) 안에서 이루어짐 for i in range(len(cores)): # r이 i의 약수 일 때 n-=1 if r%cores[i]==0: n-=1 if n==0: answer=i+1 return answer
디스크 컨트롤러 (힙, 우선순위 큐)
·
Coding Test/programmers
https://school.programmers.co.kr/learn/courses/30/lessons/42627 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 분석 리스트 끝나는 시간 정렬해서 풀 경우 (1,3)(0,2) ➔ 시작 불가하므로 불가능 풀이 from heapq import heappush, heappop def solution(jobs): answer=0 h=[] pre=-1 # 직전 종료 시각 i=0 # 현재 시각 cnt=0 # 처리개수 while cnt
로그인 성공?
·
Coding Test/programmers
def solution(id_pw, db): for x in db: if x[0]==id_pw[0]: if x[1]==id_pw[1]: return "login" else: return "wrong pw" return "fail"