일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- Python Code
- iterator
- Convert Sorted List to Binary Search Tree
- 315. Count of Smaller Numbers After Self
- attribute
- 파이썬
- Python Implementation
- kaggle
- data science
- 밴픽
- 프로그래머스
- 30. Substring with Concatenation of All Words
- 컴퓨터의 구조
- Regular Expression
- 715. Range Module
- concurrency
- Generator
- 109. Convert Sorted List to Binary Search Tree
- DWG
- 시바견
- LeetCode
- 운영체제
- Class
- Substring with Concatenation of All Words
- t1
- Protocol
- Decorator
- Python
- shiba
- 43. Multiply Strings
- Today
- Total
목록Computer Science (392)
Scribbling
102번 문제를 풀면 하나 더 주는 공짜 문제. 밑의 코드만 추가해준다. for i in range(len(ret)): if i % 2 == 1: ret[i].reverse() https://focalpoint.tistory.com/128 LeetCode: 102. Binary Tree Level Order Traversal - 시바견의 끄적임 BFS하면서 기록해준다. from collections import deque # Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None): # self.val = val # self.left = left # s.. focalpoint...
BFS하면서 기록해준다. from collections import deque # Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None): # self.val = val # self.left = left # self.right = right class Solution: def levelOrder(self, root: Optional[TreeNode]) -> List[List[int]]: if not root: return [] ret = [] q = deque() q.append((root, 0)) while q: cur_node, cur_level = q.popleft() ..
1. 가상 메모리 컴퓨터마다 실제 메모리의 크기는 다르다. 가상 메모리는 물리 메모리의 크기와 상관없이 메모리를 이용할 수 있도록 지원하는 기술이다. 프로그래머는 가상 메모리 덕분에 물리 메모리의 크기에 구애받지 않고 작업할 수 있는 작업 공간을 얻게 되는 셈이다. 현대 메모리 관리의 가장 큰 특징은 물리 메모리의 크기와 프로세스가 올라갈 메모리의 위치를 신경 쓰지 않고 프로그래밍하도록 지원한다는 것이다. 이러한 메모리 시스템을 가상 메모리(Virtual Memory)라고 한다. 모든 프로세스는 물리 메모리와 별개로 자신이 메모리의 어느 위치에 상관없이 0번지부터 시작하는 연속된 메모리 공간을 가진다. 메모리 관리자는 물리 메모리의 부족한 부분을 스왑 영역으로 보충한다. 즉 물리 메모리가 꽉 찼을 때 일..
Generator를 이용한 해법 def solution(answers): def gen1(): candidates = [1, 2, 3, 4, 5] while True: for candidate in candidates: yield candidate def gen2(): candidates = [2, 1, 2, 3, 2, 4, 2, 5] while True: for candidate in candidates: yield candidate def gen3(): candidates = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5] while True: for candidate in candidates: yield candidate g1 = gen1() g2 = gen2() g3 = gen3() ans..
x * y = brown + yellow (x-2) * (y-2) = yellow --> 모든 정수 조합 완전 탐색 def solution(brown, yellow): answer = [] xy_product = brown + yellow candidates = [] for i in range(1, xy_product//2+1): if xy_product % i == 0: candidates.append((xy_product//i, i)) for candidate in candidates: if (candidate[0]-2) * (candidate[1]-2) == yellow: return candidate
def solution(numbers): def is_prime(number): if number == 1: return False i = 2 while i * i
딱 봐도 정렬 후 Binary Search하면 된다. 매번 그렇듯 프로그래머스 지문은 극혐이다. from bisect import bisect_left def solution(citations): answer = 0 citations.sort() l, r = 0, citations[len(citations) - 1] while l = mid: answer = max(answer, mid) l = mid + 1 else: r = mid - 1 return answer
import heapq def solution(operations): answer = [] h = [] for operation in operations: opt, num = operation.split(' ') if opt == 'I': heapq.heappush(h, int(num)) else: if num == '-1': if h: heapq.heappop(h) # 최대 값 삭제 else: if h: h.pop(h.index(max(h))) heapq.heapify(h) if not h: return [0, 0] else: return [max(h), h[0]] return answer
Priority Queue를 이용하면 쉽게 풀 수 있다. 알고리즘은 '대기 큐에 들어온 Task 중 수행 시간이 가장 짧은 Task를 먼저 처리한다'가 답이다. 이는 운영체제 CPU 스케줄링 방식 중 하나인 SJF (Shortest Job First)와 유사하다. SJF가 궁금하다면, https://focalpoint.tistory.com/96?category=918151 쉽게 배우는 운영체제 내용 정리 - Chapter 04 CPU 스케줄링 1. 스케줄링 CPU 스케줄링은 CPU에 어떤 작업을 배정할지 결정하는 것이다. 컴퓨터 시스템의 효율은 이에 따라 달라진다. 앞서 배운 것 처럼, 프로세스는 생성 상태, 준비 상태, 실행 상태, 대기 상 focalpoint.tistory.com import heap..