일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 프로그래머스
- Protocol
- Python
- 30. Substring with Concatenation of All Words
- 315. Count of Smaller Numbers After Self
- 밴픽
- kaggle
- Python Implementation
- Convert Sorted List to Binary Search Tree
- data science
- Python Code
- 43. Multiply Strings
- 109. Convert Sorted List to Binary Search Tree
- 운영체제
- 파이썬
- LeetCode
- Substring with Concatenation of All Words
- concurrency
- shiba
- 컴퓨터의 구조
- iterator
- DWG
- 시바견
- 715. Range Module
- t1
- Regular Expression
- Class
- attribute
- Decorator
- Today
- Total
목록LeetCode (205)
Scribbling
class Solution: def fourSum(self, nums: List[int], target: int) -> List[List[int]]: ret = [] nums.sort() previ = None for i in range(len(nums)-3): if nums[i] == previ: continue prevj = None for j in range(i+1, len(nums)-2): if nums[j] == prevj: continue preSum = nums[i] + nums[j] l, r = j + 1, len(nums) - 1 while l < r: summation = preSum + nums[l] + nums[r] if summation < target: l += 1 elif su..
class Solution: def letterCombinations(self, digits: str) -> List[str]: if not digits: return [] ret_list = [] x = [ [], [], ['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i'], ['j', 'k', 'l'], ['m', 'n', 'o'], ['p', 'q', 'r', 's'], ['t', 'u', 'v'], ['w', 'x', 'y', 'z'], ] def save_comb(digits, string): if not digits: ret_list.append(string) return char_list = x[int(digits[0])] for char in char_l..
class Solution: def threeSumClosest(self, nums: List[int], target: int) -> int: ret = int(1e9) nums.sort() for i in range(0, len(nums)-2): l = i + 1 r = len(nums) - 1 while l < r: now_sum = nums[i] + nums[l] + nums[r] if now_sum == target: return target elif now_sum < target: if abs(now_sum - target) < abs(ret - target): ret = now_sum l += 1 else: if abs(now_sum - target) < abs(ret - target): re..
class Solution: def threeSum(self, nums: List[int]) -> List[List[int]]: nums.sort() N, ret = len(nums), [] for i in range(N): if i > 0 and nums[i] == nums[i-1]: continue target = -nums[i] l, r = i + 1, N - 1 while l target: r -= 1 else: l += 1 ..
Greedy하게... class Solution: def maxArea(self, height: List[int]) -> int: max_Area = 0 l = 0 r = len(height) - 1 while l height[l]: l = next_l break if next_l == len(height) - 1: break else: for next_r in range(r-1, -1, -1): if height[next_..
class Solution: def myAtoi(self, s: str) -> int: def delete_whitspace(s): idx = 0 while idx upper_limit: return upper_limit return num if len(s) == 0: return 0 s = delete_whitspace(s) if not s: return 0 first_char = s[0] if firs..
class Solution: def convert(self, s: str, numRows: int) -> str: if numRows == 1: return s board = [[] for _ in range(numRows)] denom = 2 * numRows - 2 for i, char in enumerate(s): remainder = i % denom if remainder < numRows: board[remainder].append(char) else: board[2 * numRows - remainder - 2].append(char) ret = '' for i in range(len(board)): for j in board[i]: ret += j return ret
위상정렬을 이용한다. class Solution: def canFinish(self, numCourses: int, prerequisites: List[List[int]]) -> bool: indegrees = [0] * numCourses graph = [[] for _ in range(numCourses)] for v, u in prerequisites: graph[u].append(v) indegrees[v] += 1 q = [] for node, indegree in enumerate(indegrees): if indegree == 0: q.append(node) while q: u = q.pop() for v in graph[u]: indegrees[v] -= 1 if indegrees[v] =..
class Solution: def minCostConnectPoints(self, points: List[List[int]]) -> int: def calc_Dist(p1, p2): d1 = abs(p1[0] - p2[0]) d2 = abs(p1[1] - p2[1]) return d1 + d2 def find_parent(parent, a): if parent[a] == a: return a parent[a] = find_parent(parent, parent[a]) return parent[a] def union_parent(parent, a, b): a = find_parent(parent, a) b = find_parent(parent, b) if a < b: parent[b] = a else: ..
Dynamic Programming을 이용한 방법: X + + X 는 Palindrome Substring이다는 특성을 이용한다. 위를 bottom-up으로 구현하려면, 문자열의 길이가 커지는 순(1, 2, 3, ....) 으로 DP를 연산하면 된다. class Solution: def longestPalindrome(self, s: str) -> str: ret = "" is_Palindrome = [[False] * len(s) for _ in range(len(s))] for i in range(len(s)): is_Palindrome[i][i] = True ret = s[i:i+1] for i in range(len(s)-1): if s[i] == s[i+1]: is_Palindrome[i][i+..