목록algorithm (97)
on my way
https://school.programmers.co.kr/learn/courses/30/lessons/42583 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr# 1트 (돌아가긴 하나 비효율)from collections import dequedef solution(bridge_length, weight, truck_weights): i, cnt, flag = 0, 0, True time, queue = deque(), deque() while True: cnt += 1 time = deque([t+1 for t in time]) if time an..
https://school.programmers.co.kr/learn/courses/30/lessons/42586import mathdef solution(progresses, speeds): days = [math.ceil((100-p)/s) for p, s in zip(progresses, speeds)] answer = [] cur, func = 0, 0 for i, d in enumerate(days): if cur 먼저 소요일을 구하고, 소요일 배열을 기준으로 같이 배포될 수 있을지를 순회한다.cur는 기준배포일, func은 기능 수를 카운트하는 변수기준 배포일보다 큰 값이 나오면 새 그룹이므로 그 전까지 answer에 기능의 수를 넣고 기준배포일과 기능수 초기..
https://www.acmicpc.net/problem/2164from collections import dequeimport sysqueue = deque(range(1, int(sys.stdin.readline())+1))while len(queue) > 1: queue.popleft() queue.rotate(-1)print(queue[0])
https://school.programmers.co.kr/learn/courses/30/lessons/42584def solution(prices): N = len(prices) answer = [0 for _ in range(N)] stack = [] for now, price in enumerate(prices): # 스택 인덱스 가격과 현재 가격 비교. # 마지막 가격이 현재가격보다 크면 가격 떨어진 것이므로 인덱스 꺼냄 while stack and prices[stack[-1]] > price: idx = stack.pop() answer[idx] = now - idx # 현재 인덱스 - ..
https://school.programmers.co.kr/learn/courses/30/lessons/76502 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr# 리팩토링 전def solution(s): result = 0 for _ in range(len(s)): s = s[1:] + s[0] stack = [] for c in s: if c in '({[': stack.append(c) else: if not stack: break if c==')' and s..
https://www.acmicpc.net/problem/1874 처음엔 문제부터 이해하기 어려웠는데스택에 1부터 n까지 숫자에 대해 하나하나 수를 push, 해당 수이면 pop하고, 다음 수를 탐색하고.. 이런 과정의 반복1. push 1 (+), push 2 (+), push 3 (+), push 4 (+) 현재 스택: [1, 2, 3, 4] 수열에서 필요한 숫자: 4 -> pop 4 (-) 현재 스택: [1, 2, 3]2. pop 3 (-) 현재 스택: [1, 2]3. push 5 (+), push 6 (+) 현재 스택: [1, 2, 5, 6] 수열에서 필요한 숫자: 6 -> pop 6 (-) 현재 스택: [1, 2, 5]4. push 7 (+), push 8 (+)..