본문 바로가기

분류 전체보기

(158)
99클럽 코테 스터디 35일차 TIL, 프로그래머스 / 퍼즐 조각 채우기 🔑 오늘의 학습 키워드 BFS, 구현🔗 문제링크 https://school.programmers.co.kr/learn/courses/30/lessons/84021 from collections import dequedef solution(game_board, table): answer = 0 n = len(game_board) directions = [(1, 0), (0, 1), (-1, 0), (0, -1)] def in_range(x, y): return 0  🗒️ 공부한 내용 본인의 언어로 정리하기🤔 문제를 보고 든 생각문제가 요구하는 사항이 많아서 함수단위로 우선 작성을 한다음 코드 세부 구현을 해야겠다고 생각했다.1. BFS로 구멍이랑 블록을 구분하는 함..
99클럽 코테 스터디 34일차 TIL, 프로그래머스 / 여행경로 🔑 오늘의 학습 키워드 dfs, 백트래킹🔗 문제링크 https://school.programmers.co.kr/learn/courses/30/lessons/43164 def solution(tickets): n = len(tickets) answer = [] def dfs(): if len(stack) == n+1 : a = [stack[i] for i in range(n+1)] answer.append(a) for i in range(n): if not visited[i] and stack[-1] == tickets[i][0] : visited[i] = 1 ..
99클럽 코테 스터디 33일차 TIL, 프로그래머스 / 단어 변환 🔑 오늘의 학습 키워드 bfs🔗 문제링크 https://school.programmers.co.kr/learn/courses/30/lessons/43163 def solution(begin, target, words): # 못찾는 경우 if target not in set(words): return 0 answer = 0 stack = [(begin,0)] visited = set() visited.add(begin) while stack: start,cnt = stack.pop() for word in words: if word not in visited: wron..
99클럽 코테 스터디 32일차 TIL, 프로그래머스 / 아이템 줍기 🔑 오늘의 학습 키워드 : bfs, 좌표 표현🔗 문제링크 https://school.programmers.co.kr/learn/courses/30/lessons/87694 from collections import dequedef solution(rectangle, characterX, characterY, itemX, itemY): answer = 0 grid = [[0] * 101 for _ in range (101)] for x1,y1,x2,y2 in rectangle : x1, y1, x2, y2 = x1 * 2, y1 * 2, x2 * 2, y2 * 2 for i in range (x1,x2+1): for j in range..
99클럽 코테 스터디 31일차 TIL, 프로그래머스 / 네트워크 🔑 오늘의 학습 키워드 bfs🔗 문제링크 https://school.programmers.co.kr/learn/courses/30/lessons/43162 from collections import dequedef solution(n, computers): answer = 0 queue = deque([]) visited = set() def bfs(start): queue.append(start) while queue: node = queue.popleft() for idx, connect in enumerate(computers[node]): if connect == 1 and ..
99클럽 코테 스터디 30일차 TIL, leetcode / Minimum Operations to Make a Subsequence 🔑 오늘의 학습 키워드 : 이분탐색🔗 문제링크 https://leetcode.com/problems/minimum-operations-to-make-a-subsequence/ '''이분 탐색을 사용하려면 우선 정렬된 리스트가 필요함이 경우, 정렬을 한 리스트를 사용하면 안됨target 리스트는 중복 없는 리스트 -> 고유의 값을 가진다면 -> 인덱스 역할을 할 수 있는 애 아닐까?target = [6,4,8,1,3,2], arr = [4,7,6,2,3,8,6,1]target = [1,2,3,4,5,6], arr = [2,x,1,6,5,3,1,4]이렇게 생각해보니? 가장 증가하는 길이가 긴 수열을 구하는 것을 구한 다음전체 length에서 가장 길이가 긴 수열의 길이만큼을 뺴면 되지 않을까?가장 증가하..
99클럽 코테 스터디 29일차 TIL, leet code / Maximum Profit in Job Scheduling 🔑 오늘의 학습 키워드 dp, binary search🔗 문제링크 https://leetcode.com/problems/maximum-profit-in-job-scheduling/submissions/1360938614/ class Solution: def jobScheduling(self, startTime: List[int], endTime: List[int], profit: List[int]) -> int: tasks = [(s,e,p) for s,e,p in zip(startTime,endTime,profit)] tasks.sort(key = lambda x : x[1]) dp = [(0, 0)] # (end_time, max_profit) ..
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..