일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- data science
- 운영체제
- 컴퓨터의 구조
- Substring with Concatenation of All Words
- concurrency
- Class
- 43. Multiply Strings
- DWG
- Python Implementation
- 30. Substring with Concatenation of All Words
- kaggle
- Decorator
- Protocol
- Python Code
- LeetCode
- 715. Range Module
- Python
- 시바견
- Regular Expression
- Convert Sorted List to Binary Search Tree
- 프로그래머스
- Generator
- 파이썬
- 밴픽
- 315. Count of Smaller Numbers After Self
- 109. Convert Sorted List to Binary Search Tree
- t1
- iterator
- attribute
- shiba
- Today
- Total
목록Computer Science (392)
Scribbling
class Solution: def totalNQueens(self, n: int) -> int: self.ret = 0 self.solver(n, [], [], []) return self.ret def solver(self, n, queens, sumyx, subyx): if len(queens) == n: self.ret += 1 return for i in range(n): y, x = len(queens), i if (i not in queens) and ((y+x) not in sumyx) and ((y-x) not in subyx): self.solver(n, queens+[i], sumyx+[(y+x)], subyx+[(y-x)])

오늘도 무지성 스텍 쌓아버린 나의 코드 from copy import deepcopy class Solution: def solveNQueens(self, n: int) -> List[List[str]]: ret = [] board = [['.'] * n for _ in range(n)] self.solver(n, board, 0, ret) return ret def solver(self, n, board, num_Q, ret): if num_Q == n: ret_board = [] for i in range(n): temp = list(board[i]) for j in range(len(temp)): if temp[j] != 'Q': temp[j] = '.' ret_board.append(''.join..
여러 경우의 수를 다 고려해봐야 한다. 어려운 문제이긴하나, dp를 써야한다는 점과 dp table의 크기를 정하는 것이 핵심. 여기서 matched[i][j]: p[i-1]까지의 패턴 문자열이 s[j-1] 문자열을 cover함을 의미. class Solution(object): def isMatch(self, s, p): matched = [[False] * (len(s)+1) for _ in range(len(p)+1)] matched[0][0] = True for i in range(2, len(p)+1): if p[i-1] == '*': matched[i][0] = matched[i-2][0] for i in range(1, len(p)+1): for j in range(1, len(s)+1): ..
class Solution: def multiply(self, num1: str, num2: str) -> str: if num1 == '0' or num2 == '0': return '0' ret = [0] * (len(num1) + len(num2)) for i in range(len(num1)-1, -1, -1): carry = 0 for j in range(len(num2)-1, -1, -1): temp = ret[i+j+1] + int(num1[i]) * int(num2[j]) + carry carry = temp // 10 ret[i+j+1] = temp % 10 ret[i] = carry ret = ''.join(map(str, ret)) return ret.lstrip('0')
욕심쟁이는 풀 수 있는 문제 class Solution: def jump(self, nums: List[int]) -> int: if len(nums) == 1: return 0 now, jump = 0, 0 while True: if now + nums[now] >= len(nums) - 1: return jump + 1 val, next_idx = -1, -1 for i in range(now+1, min(now+nums[now]+1, len(nums))): if i + nums[i] > val: val = i + nums[i] next_idx = i now = next_idx jump += 1
class Solution: def multiply(self, num1: str, num2: str) -> str: if num1 == '0' or num2 == '0': return '0' ret = [0] * (len(num1) + len(num2)) for i in range(len(num1)-1, -1, -1): carry = 0 for j in range(len(num2)-1, -1, -1): temp = ret[i+j+1] + int(num1[i]) * int(num2[j]) + carry carry = temp // 10 ret[i+j+1] = temp % 10 ret[i] = carry ret = ''.join(map(str, ret)) return ret.lstrip('0')
The key observations to solve this problems: - right >= left + 2, to contain water - if we have a max height either at left or right position, then we can calculate water in the opposite position. class Solution: def trap(self, height: List[int]) -> int: ret = 0 l, r = 0, len(height) - 1 leftmax, rightmax = height[l], height[r] while r - l >= 2: curmax = max(leftmax, rightmax) if curmax == right..
class Solution: def searchRange(self, nums: List[int], target: int) -> List[int]: return self.binary_search(nums, 0, len(nums)-1, target) def binary_search(self, nums, left, right, target): if left > right: return [-1, -1] mid = (left + right) // 2 mid_val = nums[mid] if mid_val > target: return self.binary_search(nums, left, mid-1, target) elif mid_val < target: return self.binary_search(nums, ..
class Solution: def search(self, nums: List[int], target: int) -> int: left, right = 0, len(nums) - 1 while left = nums[left]: if nums[left]
1. 멀티태스킹: 컴퓨터가 한 번에 둘 이상의 작업을 수행하는 것. 과거에는 CPU가 하나여서 여러 작업을 동시에 수행하는 척만 했다면, 이제는 멀티코어 프로세서가 대세가 되어 컴퓨터가 실제로 한 번에 둘 이상의 일을 하고 있다. - 경합 조건과 락: 일부 연산에 대하여 근본적으로 멀티태스킹을 막아야 한다. - 프로세스: 프로세스 (Process)는 사용자 공간 (User Space)에서 실행되는 프로그램이다. 멀티코어 시스템에서는 여러 프로그램이 병렬로 실행될 수 있다. - 스레드: 스레드 (Thread)는 정적인 데이터와 힙을 공유하지만 자체적으로 스택을 갖는 프로그램의 일부분을 말한다. 한 스레드에서 다른 스레드로 실행이 넘어갈 때는 스레드 스케줄러 (Thread Scheduler)가 CPU 레지스..