일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- Generator
- 715. Range Module
- Decorator
- 시바견
- attribute
- iterator
- 30. Substring with Concatenation of All Words
- LeetCode
- Substring with Concatenation of All Words
- shiba
- 315. Count of Smaller Numbers After Self
- 운영체제
- Class
- Protocol
- Python Code
- concurrency
- kaggle
- 109. Convert Sorted List to Binary Search Tree
- Python Implementation
- 컴퓨터의 구조
- Convert Sorted List to Binary Search Tree
- 43. Multiply Strings
- Regular Expression
- DWG
- data science
- 밴픽
- Python
- t1
- 파이썬
- 프로그래머스
- Today
- Total
목록분류 전체보기 (407)
Scribbling
1. 운영체제 1.1. 운영체제 운영체제 (Operating System)란? 윈도우, Mac Os, 유닉스 (Unix), 리눅스 (Linux) 등이 운영체제에 해당된다. 스마트폰에도 운영체제가 있는데, 애플의 iOS와 구글의 안드로이드가 대표적이다. CPU 성능이 낮고 메모리 크기가 작은 시스템에 내장하도록 만든 운영체제는 임베디드 시스템 (Embedded System)이라고 한다. 1.2. 운영체제의 필요성 - 운영체제가 없는 기계는 만들 당시 구현한 기능 외에 다른 기능을 추가하거나 성능을 향상 할 수 없다. 반면 운영체제가 있는 기계는 새로운 기능의 추가나 성능 변경이 가능하다. - 운영체제는 자원 관리 (Resource Management)라는 중요한 역할을 수행한다. 컴퓨터에 부착된 모든 장치..
class Solution: def canJump(self, nums): destination = len(nums) - 1 for i in range(len(nums)-2, -1, -1): if i + nums[i] >= destination: destination = i return destination == 0
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, ..