일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 프로그래머스
- 30. Substring with Concatenation of All Words
- 715. Range Module
- t1
- 파이썬
- Substring with Concatenation of All Words
- concurrency
- shiba
- iterator
- LeetCode
- kaggle
- DWG
- Protocol
- 밴픽
- Class
- 315. Count of Smaller Numbers After Self
- Regular Expression
- 43. Multiply Strings
- 109. Convert Sorted List to Binary Search Tree
- 운영체제
- data science
- Convert Sorted List to Binary Search Tree
- Generator
- Python Code
- Python
- 컴퓨터의 구조
- 시바견
- Python Implementation
- attribute
- Decorator
- Today
- Total
목록LeetCode (205)
Scribbling
class Solution: def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]: ret = [] arr = [0] self.helper(ret, arr, candidates, target) return ret def helper(self, ret, arr, candidates, target): _sum = sum(arr) if _sum > target: return if _sum == target: ret.append(arr[1:]) return for candidate in candidates: last_input = arr[-1] if candidate >= last_input: next_arr = arr.c..
무지성 포칼포인트의 답... class Solution: def longestValidParentheses(self, s: str) -> int: if not s: return 0 mem = [0] * len(s) stack = [] length = 0 for i in range(len(s)): char = s[i] if char == '(': stack.append(char) length = 0 else: if not stack: length = 0 else: top = stack.pop() if top == '(': length += 2 if i - length >= 0 and s[i-length] == ')': length += mem[i-length] else: length = 0 mem[i] =..
* Note: shift left is the same as multiplying by two. class Solution: def divide(self, dividend: int, divisor: int) -> int: # Overflow if dividend == -2**31 and divisor == -1: return 2**31 - 1 # Positive? positive = (dividend > 0) is (divisor > 0) dividend = abs(dividend) divisor = abs(divisor) res = 0 subtract = divisor while divisor
class Solution: def myPow(self, x: float, n: int) -> float: if n == 0: return 1 if x == 1: return 1 if x == -1: if abs(n) % 2 == 0: return 1 else: return -1 if x == 0: return 0 n_sign = True if n > 0 else False res = 1 count = 0 while count < abs(n): multiplier = x step = 1 while step
O(NK)... from collections import deque, defaultdict class Solution: def findSubstring(self, s: str, words: List[str]) -> List[int]: n = len(s) m = len(words) len_words = len(words[0]) if n < m * len_words: return [] ret = set() ans = defaultdict(int) for word in words: ans[word] += 1 words = set(words) for i in range(0, len_words): comp = defaultdict(int) q = deque([], maxlen=m) while i
class Solution: def removeDuplicates(self, nums: List[int]) -> int: prev = None i = 0 for num in nums: if num != prev: nums[i] = num prev = num i += 1 return i
문제의 쉬운 version... 재귀를 이용해서 푸는 방법을 익혀두자. # Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.next = next class Solution: def swapPairs(self, head: Optional[ListNode]) -> Optional[ListNode]: k = 2 count, node = 0, head while node and count < k: node = node.next count += 1 if count < k: return head n..
Recursion solution. Time Complexity: O(N), Memory Complexity: O(1) # Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.next = next class Solution: def reverseKGroup(self, head: Optional[ListNode], k: int) -> Optional[ListNode]: return self.helper(head, k) def helper(self, node, k): if not node: return None cur = node for i in ran..
class Solution: def generateParenthesis(self, n: int) -> List[str]: self.ret = [] self.helper(n, n, '') return self.ret def helper(self, l, r, path): if l == 0: self.ret.append(path + (')' * r)) return if l == r: self.helper(l-1, r, path + '(') else: self.helper(l-1, r, path + '(') self.helper(l, r-1, path + ')')
# Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.next = next class Solution: def removeNthFromEnd(self, head: Optional[ListNode], n: int) -> Optional[ListNode]: length = 0 cur = head while cur != None: length += 1 cur = cur.next prv, cur = None, head num_move = length - n while num_move > 0: prv = cur cur = cur.next num_move -..