본문 바로가기

프로그래머스121

[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++, 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.
억억단을 외우자 - Python https://school.programmers.co.kr/learn/courses/30/lessons/138475 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr  코드 & 풀이 def solution(e, starts): num_count = [0] * (e + 1) for i in range(1, int(e ** 0.5) + 1): for j in range(i, e // i + 1): num = i * j if i == j: num_count[num] += 1 else: .. 2025. 2. 21.