파이썬59 백준9012. 괄호 - Python, stack 출처 : https://www.acmicpc.net/problem/9012 코드 & 풀이 import sys# 입력 처리data = sys.stdin.read().splitlines()N = int(data.pop(0))def VPS(pstring): stack = [] for parenthesis in pstring: if parenthesis == ')': if not stack: return "NO" stack.pop() else: stack.append(parenthesis) return "NO" if stack else "YES"answer = ""for _ in.. 2025. 5. 10. 백준1021. 회전하는 큐 - Python, deque, rotate 출처 : https://www.acmicpc.net/problem/1021 코드 & 풀이 import sysfrom collections import deque# 입력 처리data = sys.stdin.read().splitlines()N, M = map(int, data.pop(0).split(" "))dq = deque()for i in range(1, N + 1): dq.append(i)targets = [int(i) for i in list(data.pop(0).split(" "))]answer = 0for target in targets: idx = dq.index(target) size = len(dq) if idx == 0: dq.popleft() .. 2025. 5. 9. 조이스틱 - Python, 그리디 https://school.programmers.co.kr/learn/courses/30/lessons/42860 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 코드 & 풀이 def solution(name): answer = 0 size = len(name) for ch in name: answer += min(ord(ch) - ord('A'), ord('Z') - ord(ch) + 1) move = size - 1 for i in range(size): next_idx = i + 1 while next_idx 위, 아래 키와 왼쪽,.. 2025. 5. 7. [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. 억억단을 외우자 - 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. 부대복귀 - Python, BFS https://school.programmers.co.kr/learn/courses/30/lessons/132266 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 코드 & 풀이 from collections import dequedef solution(n, roads, sources, destination): graph = [[] for _ in range(n + 1)] for start, end in roads: graph[start].append(end) graph[end].append(start) distances = [-1] * (n + 1) .. 2025. 2. 17. 이전 1 2 3 4 ··· 10 다음