본문 바로가기

Algorithm/programmers20

[프로그래머스] 조건에 부합하는 중고거래 댓글 조회하기 조건에 부합하는 중고거래 댓글 조회하기 | Lv.1 https://school.programmers.co.kr/learn/courses/30/lessons/164673 작성 코드 (성공) SELECT USED_GOODS_BOARD.TITLE AS TITLE, USED_GOODS_BOARD.BOARD_ID, USED_GOODS_REPLY.REPLY_ID, USED_GOODS_REPLY.WRITER_ID, USED_GOODS_REPLY.CONTENTS, DATE_FORMAT(USED_GOODS_REPLY.CREATED_DATE, '%Y-%m-%d') AS DATE_FORMAT FROM USED_GOODS_BOARD RIGHT JOIN USED_GOODS_REPLY ON USED_GOODS_REPLY.BOAR.. 2024. 4. 5.
[프로그래머스] 징검다리 징검다리 | Lv.4 https://school.programmers.co.kr/learn/courses/30/lessons/43236 작성 코드 (시간 초과) from itertools import combinations def solution(distance, rocks, n): answer = 0 rocks.sort() # 제거할 rock을 combination으로 생성 combination = list(combinations(rocks, n)) for comb in combination: min_dist = distance before = 0 for rock in rocks: # rock 이 comb에 없으면, 즉 제거할 바위가 아니면 if rock not in comb: min_dist = mi.. 2023. 5. 21.
[프로그래머스] 입국심사 입국심사 | Lv.3 https://school.programmers.co.kr/learn/courses/30/lessons/43238 작성 코드 (시간 초과) def solution(n, times): answer = 0 wait = times[:] for person in range(n): # 가장 짧게 끝나는 곳의 인덱스 반환 min_wait = wait.index(min(wait)) # 해당 번호에 줄을 선다 -> 이후 다른 사람은 시간이 더 걸린다 -> 더해준다! wait[min_wait] += times[min_wait] # 입국 심사가 진행되는 시간까지 포함이라 맨 마지막에는 진행 시간을 빼줘야 함 return wait[min_wait] - times[min_wait] 최소 값이라 힙을 쓰고.. 2023. 5. 19.
[프로그래머스] H-Index H-Index | Lv.2https://school.programmers.co.kr/learn/courses/30/lessons/42747    작성 코드 def solution(citations): citations.sort() # h편 이상 인용되는 것을 세야하니 max 값은 citations의 길이를 넘을 수 없음 for i in range(len(citations), 1, -1): if i  [3, 0, 6, 1, 5] -> [0, 1, 3, 5, 6] ilen(citations) - i 5번 이상 인용50citation[0] 부터는 i 보다 크거나 같아야 함4번 이상 인용41citation[1] 부터는 i 보다 크거나 같아야 함3번 이상 인용32citation.. 2023. 5. 18.
[프로그래머스] 디스크 컨트롤러 https://school.programmers.co.kr/learn/courses/30/lessons/42627?language=ruby 작성 코드 (실패) from collections import deque def solution(jobs): visit = deque(jobs) def dfs(total_time, visited, depth, wait_time, min_wait_time): print(1, total_time, visited, depth, min_wait_time) if depth == len(jobs): min_wait_time = min(min_wait_time, total_time) return min_wait_time for idx1, v in enumerate(visited).. 2023. 5. 17.
[프로그래머스] 더 맵게 더 맵게 | Lv.2 https://school.programmers.co.kr/learn/courses/30/lessons/42626 작성 코드 queue 이용한 풀이 from collections import deque def solution(scoville, K): answer = 0 queue = deque(sorted(scoville)) while queue: if queue[0] >= K: return answer elif len(queue) < 2: return -1 else: a = queue.popleft() b = queue.popleft() queue.appendleft(a + 2 * b) print(queue) 문제 분류는 heap이었지만 queue로도 풀 수 있지 않을까 생각함 [.. 2023. 5. 15.
반응형