본문 바로가기

프로그래머스143

[PCCP 기출문제] 2번 > 석유 시추 - Python, bfs, 누적합 https://school.programmers.co.kr/learn/courses/30/lessons/250136 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr  코드 & 풀이 from collections import dequedef solution(land): n, m = len(land), len(land[0]) visited = [[False] * m for _ in range(n)] def find_oil(i, j): direct = [(-1, 0), (1, 0), (0, -1), (0, 1)] q = deque([(i, j)]).. 2025. 2. 27.
[PCCP 기출문제] 3번 > 충돌위험 찾기 - Python, Counter https://school.programmers.co.kr/learn/courses/30/lessons/340211 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr  코드 & 풀이 from collections import Counterdef solution(points, routes): # 출발지부터 도착지까지 검사해야 됨 # 출발지에서 검사 한 번 하고 시작 or 공회전 한 번 돌리고 시작 new_routes = [] for route in routes: step = 0 x, y = points[route[0] - 1] tmp_route = .. 2025. 2. 27.
[PCCP 기출문제] 2번 > 퍼즐 게임 챌린지 - Python, binary_search(이진 탐색) https://school.programmers.co.kr/learn/courses/30/lessons/340212 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr  코드 & 풀이 def solution(diffs, times, limit): # diff level 일 경우 diff - level 번 틀리고, 틀릴 때마다 time_cur 소요 # 추가로 time_prev 만큼의 시간 추가 소요해서 이전 퍼즐을 다시 풀어야 함 # 이전 문제를 다시 풀 때는 무조건 틀리지 않음 # 다시 풀리는 데 걸리는 시간 = (한 번 틀릴 때 걸리는 시간) * 틀린 횟수 + 이전 퍼즐로 돌아가는 .. 2025. 2. 26.
올바른 괄호 - C++, Stack https://school.programmers.co.kr/learn/courses/30/lessons/12909 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr  코드 & 풀이 #include #include #include using namespace std;bool solution(string s){ bool answer = true; stack c_stack; for (char c : s) { if (c == '(') { c_stack.push(c); }else { if (!c_stack.empty()) { .. 2025. 2. 22.
기능 개발 - C++, Queue 주소 코드 & 풀이 vector solution(vector progresses, vector speeds) { vector answer; int day; int max_day = 0; for (int i = 0; i   주석 그대로임 각 작업이 완료되는데 필요한 일수를 계산해서 이를 기반으로 답을 구해갑니다. 현재 최대 일수보다 크다는 것은 지금 완료 되지 않는 다는 것을 뜻하니까, anwer에 새로 추가 현대 최대 일수보다 작거나 같다면 작업이 완료되고 대기하고 있었던 거니까 추가하는 게 아니고 기존의 것에 + 1을 해줍니다. 2025. 2. 22.
최빈값 구하기 - C++, unordered_map, auto 주소 코드 & 풀이 #include #include using namespace std;int solution(vector array) { unordered_map freq; for (int num : array) freq[num]++; int max_cnt = 0, mode = -1; bool is_duplicate = false; for (auto &[num, count] : freq){ if(count > max_cnt){ max_cnt = count; mode = num; is_duplicate = false; } else if(count == max_cnt){ .. 2025. 2. 22.