본문 바로가기
PROGRAMMERS 76502: 괄호 회전하기 Link : https://programmers.co.kr/learn/courses/30/lessons/76502 Python 더보기 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 from collections import deque def solution(s): deq = deque(s[:]) result = 0 length = len(s) for i in range(length): temp = deq.popleft() deq.append(temp) stack = [] for i in deq: if len(stack) == 0: if i in [')', ']', '}']: break stack.app.. 2021. 6. 21.
PROGRAMMERS 12985: 예상 대진표 Link : programmers.co.kr/learn/courses/30/lessons/12985 Python 더보기 1 2 3 4 5 6 7 8 9 10 11 12 13 14 def solution(n, a, b): a -= 1 b -= 1 matching_list = [1 if i == a or i == b else 0 for i in range(n)] counting = 1 while len(matching_list) > 2: for i in range(0, n, 2): if matching_list[i] == 1 and matching_list[i + 1] == 1: return counting matching_list = [1 if matching_list[i] == 1 or matching_.. 2021. 4. 5.
PROGRAMMERS 17684: [3차] 압축 Link : programmers.co.kr/learn/courses/30/lessons/17684 Python 더보기 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 alphabet = dict() for i in range(26): alphabet[chr(i + 65)] = i + 1 def solution(msg): maxlength = 1 answer = [] pos = 0 while pos 2021. 4. 5.
PROGRAMMERS 1844: 게임 맵 최단거리 Link : programmers.co.kr/learn/courses/30/lessons/1844 Python 더보기 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 from queue import Queue # R D L U direction = [(1, 0), (0, 1), (-1, 0), (0, -1)] def ableMove(maps, x, y): if x = len(maps): return False if maps[y][x] == 0: return False return True def solution(maps): que = Queue() que.put((0, 0, 0)) while que.qsize(): x, y,.. 2021. 4. 2.
PROGRAMMERS 49994: 방문 길이 Link : programmers.co.kr/learn/courses/30/lessons/49994 Python 더보기 1234567891011121314151617181920212223242526272829303132333435363738394041def solution(dirs): result = 0 history_path = dict() pos = (0, 0) # X Y for i in dirs: if i == 'L': if pos[0] - 1 5: continue if (pos[0], pos[1], 'R') not in history_path: history_path[(pos[0], pos[1], 'R')] = None history_path[(pos[0] + 1, pos[1], 'L')] = N.. 2021. 4. 2.