일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 43. Multiply Strings
- data science
- Protocol
- DWG
- Regular Expression
- 프로그래머스
- 715. Range Module
- 30. Substring with Concatenation of All Words
- 시바견
- 밴픽
- Decorator
- Python Implementation
- Python Code
- 운영체제
- kaggle
- 109. Convert Sorted List to Binary Search Tree
- t1
- 파이썬
- Convert Sorted List to Binary Search Tree
- 315. Count of Smaller Numbers After Self
- LeetCode
- Python
- concurrency
- Class
- Generator
- Substring with Concatenation of All Words
- iterator
- 컴퓨터의 구조
- attribute
- shiba
- Today
- Total
목록분류 전체보기 (407)
Scribbling
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 레지스..
class Solution: def nextPermutation(self, nums: List[int]) -> None: i = len(nums) - 1 while i - 1 >= 0 and nums[i-1] >= nums[i]: i -= 1 if i == 0: return nums.sort() swap_idx, swap_val = None, int(1e9) for j in range(i, len(nums)): if nums[j] > nums[i-1] and nums[j] < swap_val: swap_val = nums[j] swap_idx = j nums[i-1], nums[swap_idx] = nums[swap_idx], nums[i-1] nums[i:] = sorted(nums[i:])
Binary Search 살짝만 바꿔주자 class Solution: def searchInsert(self, nums: List[int], target: int) -> int: return self.binary_search(nums, 0, len(nums)-1, target) def binary_search(self, nums, l, r, target): if l == r: if target
class Solution: def groupAnagrams(self, strs: List[str]) -> List[List[str]]: from collections import defaultdict dic = defaultdict(list) for s in strs: counter = [0] * 26 for char in s: counter[ord(char) - ord('a')] += 1 dic[tuple(counter)].append(s) return [x for x in dic.values()]
The essence of solving this problem within O(N) time complexity & O(1) memory is using the nums array itself as the hash for its numbers. That is, nums[i] should contain the information about whether i-1 is in nums or not. Here, we should come up with an algorithm that marks nums array without messing up with the original value of nums[i]. Here, I accomplish such an algorithm using negative sign..
class Solution: def permuteUnique(self, nums: List[int]) -> List[List[int]]: nums.sort() self.ret = [] self.dfs(nums, []) return self.ret def dfs(self, nums, path): if not nums: self.ret.append(path) return prev = None for i, num in enumerate(nums): if num != prev: self.dfs(nums[:i]+nums[i+1:], path+[num]) prev = num
DFS Solution. from itertools import permutations class Solution: def permute(self, nums: List[int]) -> List[List[int]]: # Using Library # return list(permutations(nums, len(nums))) ret = [] self.helper(nums, [], ret) return ret def helper(self, nums, element, ret): if not nums: ret.append(element) for i, num in enumerate(nums): self.helper(nums[:i]+nums[i+1:], element+[num], ret) A lazy solution..
class Solution: def combinationSum2(self, candidates: List[int], target: int) -> List[List[int]]: candidates.sort() self.ret = [] self.dfs(candidates, target, []) return self.ret def dfs(self, candidates, target, path): if target < 0: return if target == 0: self.ret.append(path) return prev = None for i, candidate in enumerate(candidates): if candidate != prev: prev = candidate self.dfs(candidat..
1. 고수준 / 저수준 프로그래밍 - 운영체제는 사용자 프로그램이 I/O 장치의 복잡도를 상당 부분 볼 필요 없도록 가려준다. - 브라우저 같은 복잡한 사용자 프로갬은 그 프로그램 위에 만들어진 다른 애플리케이션 프로그램들이 운영체제를 다루는 복잡도를 볼 필요 없도록 가려준다. 2. 터미널 / 장치 드라이버 / 운영체제 2.1. 터미널과 장치 드라이버 터미널은 I/O 장치이며, 사용자 프로그램은 직접 I/O 장치와 통신하지 않는다. 아래 그림처럼 운영체제가 중간에서 통신을 중재한다. 장치 드라이버는 말 그대로 특정 하드웨어 장치를 제어하는 프로그램을 의미한다. 사용자 프로그램이 특정 장치 (예컨대 I/O 장치)를 제어하기 위해서는, 시스템 콜을 통해 운영체제를 통하여 장치 드라이버의 ..