본문 바로가기

전체 글

(159)
99클럽 코테 스터디 28일차 TIL, 백준 / 스택수열 / 파이썬 🔑 오늘의 학습 키워드 : 스택🔗 문제링크 https://www.acmicpc.net/problem/1874 import sysinput = sys.stdin.readlinen = int(input())goal = [int(input()) for _ in range (n)]stack = []made = []pointer = 0answer = []for i in range (1,n+1): stack.append(i) answer.append('+') while stack and stack[-1] == goal[pointer]: made.append(stack.pop()) answer.append('-') pointer += 1if made == go..
99클럽 코테 스터디 27일차 TIL, 프로그래머스 / 공 이동 시뮬레이션 🔑 오늘의 학습 키워드 : 구현🔗 문제링크  https://school.programmers.co.kr/learn/courses/30/lessons/87391 def solution(n, m, goal_x, goal_y, queries): # 초기화 min_x, max_x = goal_x, goal_x min_y, max_y = goal_y, goal_y for command, length in queries[::-1]: if command == 0: max_y = min(m - 1, max_y + length) if min_y > 0: min_y += length elif ..
99클럽 코테 스터디 26일차 TIL, 프로그래머스 / 개인정보 수집 유효기간 🔑 오늘의 학습 키워드 : 구현🔗 문제링크 https://school.programmers.co.kr/learn/courses/30/lessons/150370 def solution(today, terms, privacies): answer = [] today = today.split('.') today = int(today[0]+today[1]+today[2]) ter = {} for term in terms: tmp = term.split() ter[tmp[0]] = tmp[1] for key, pri in enumerate(privacies): tmp = pri.split() day = list(map(int,tm..
99클럽 코테 스터디 25일차 TIL, 프로그래머스 / 순위 🔑 오늘의 학습 키워드 bfs🔗 문제링크 https://school.programmers.co.kr/learn/courses/30/lessons/49191 from collections import dequedef solution(n, results): answer = 0 left = {i+1 : [] for i in range(n)} right = {i+1 : [] for i in range(n)} for result in results: left[result[0]].append(result[1]) right[result[1]].append(result[0]) def bfs(start,lr): queue = deque([..
99클럽 코테 스터디 24일차 TIL, 프로그래머스 / 가장 먼 노드 🔑 오늘의 학습 키워드 : 그래프🔗 문제링크 https://school.programmers.co.kr/learn/courses/30/lessons/49189 from collections import dequedef solution(n, edge): answer = [0] * (n+1) graph = {i:[] for i in range (1,n+1)} for a,b in edge: graph[a].append(b) graph[b].append(a) queue = deque([(1,0)]) visited = set([1]) while queue: node,distance = queue.popleft() for next..
99클럽 코테 스터디 23일차 TIL, leetcode / IPO 🔑 오늘의 학습 키워드 heap🔗 문제링크 https://leetcode.com/problems/ipo/ # 현재 가지고 있는 상품 중에서 가장 좋은 것을 선택# 자료구조 heap을 사용해서 pop할 때마다 비교하면서 가장 좋은 것을 선택class Solution: def findMaximizedCapital(self, k: int, w: int, profits: List[int], capital: List[int]) -> int: projects = sorted(list(zip(capital, profits))) max_heap = [] i = 0 for _ in range(k): # 현재 자본(w)으로 할 수 ..
99클럽 코테 스터디 22일차 TIL, leetcode / maximal-rectangle 🔑 오늘의 학습 키워드 : 스택🔗 문제링크 https://leetcode.com/problems/maximal-rectangle/ class Solution: def maximalRectangle(self, matrix: List[List[str]]) -> int: if not matrix or not matrix[0]: return 0 rows = len(matrix) cols = len(matrix[0]) max_area = 0 heights = [0] * cols for i in range(rows): for j in range(cols): ..
99클럽 코테 스터디 19일차 TIL, 프로그래머스 / 조이스틱 🔑 오늘의 학습 키워드 : 그리디🔗 문제링크 https://school.programmers.co.kr/learn/courses/30/lessons/42860 def solution(name): if set(name) == {'A'}: return 0 a_pos = ord('A') # 'A' : 65, 'Z' : 90 z_pos = ord('Z') answer = float('inf') for i in range(len(name)//2 + 1): l_r = name[-i:] + name[:-i] #왼쪽먼저 갔다가 + 오른쪽 r_l = name[i: :-1] + name[i+1:][::-1] # 기준점에서 빠꾸 + 좌..