일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 315. Count of Smaller Numbers After Self
- 파이썬
- 43. Multiply Strings
- 30. Substring with Concatenation of All Words
- Decorator
- shiba
- Protocol
- Python Code
- data science
- Generator
- concurrency
- 프로그래머스
- Python Implementation
- t1
- Python
- 밴픽
- Substring with Concatenation of All Words
- 시바견
- 109. Convert Sorted List to Binary Search Tree
- Regular Expression
- LeetCode
- 컴퓨터의 구조
- attribute
- kaggle
- DWG
- Convert Sorted List to Binary Search Tree
- 715. Range Module
- 운영체제
- Class
- iterator
- Today
- Total
목록Computer Science (392)
Scribbling
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 장치)를 제어하기 위해서는, 시스템 콜을 통해 운영체제를 통하여 장치 드라이버의 ..
class Solution: def solveSudoku(self, board: List[List[str]]) -> None: """ Do not return anything, modify board in-place instead. """ num_left = 0 for i in range(9): for j in range(9): if board[i][j] == '.': num_left += 1 self.solver(board, num_left) def solver(self, board, num_left): if num_left == 0: return True # Search Blank -> (i, j) start_y, start_x = 0, 0 found_flag = False for t in range..
class Solution: def isValidSudoku(self, board: List[List[str]]) -> bool: for i in range(9): for j in range(9): if board[i][j] != '.': # 가로 for k in range(9): if k == j: continue if board[i][j] == board[i][k]: return False # 세로 for k in range(9): if k == i: continue if board[i][j] == board[k][j]: return False # 사각형 start_y = i // 3 * 3 start_x = j // 3 * 3 for y in range(start_y, start_y+3): for ..