일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 리트코드
- 파이썬알고리즘
- GenerativeAI
- 투포인터
- GenAI
- two-pointer
- 파이썬기초100제
- 슬라이딩윈도우
- dfs
- LeetCode
- gcp
- slidingwindow
- Python
- 파이썬
- 생성형AI
- codeup
- SQL
- array
- 니트코드
- nlp
- sql코테
- Python3
- Greedy
- 릿코드
- 알고리즘
- Stack
- stratascratch
- 코드업
- heap
- 자연어처리
- Today
- Total
목록IT (172)
Tech for good

# Definition for singly-linked list.# class ListNode:# def __init__(self, val=0, next=None):# self.val = val# self.next = nextclass Solution: def hasCycle(self, head: Optional[ListNode]) -> bool: res = set() # set -> list's unique => ex. [1,1,1,2] -> [1,2] current = head while current: if current in res: return True ..

https://neetcode.io/problems/anagram-groups NeetCode neetcode.io class Solution: def groupAnagrams(self, strs: List[str]) -> List[List[str]]: res = {} for word in strs: count = [0] * 26 for w in word: count[ord(w) - ord('a')] += 1 key = tuple(count) # print(key) if key in res: res[key].append(wo..

https://neetcode.io/problems/daily-temperatures?list=neetcode150 NeetCode neetcode.ioApproach 1 -> nest loop (time complexity: O(n^2)) class Solution: def dailyTemperatures(self, temperatures: List[int]) -> List[int]: res = [] # t = temperature[i] for i, t in enumerate(temperatures): j = i+1 while j = temperatures[j]: j+=1 ..

https://neetcode.io/problems/minimum-stack?list=neetcode150 NeetCode neetcode.ioclass MinStack: def __init__(self): self.stack = [] self.min_stack = [] def push(self, val: int) -> None: self.stack.append(val) if self.min_stack: min_stack_element = self.min_stack[-1] self.min_stack.append(min(val, min_stack_element)) else: ..

1) Recursive DFSclass Solution: def validPath(self, n: int, edges: List[List[int]], source: int, destination: int) -> bool: if source == destination: return True # Step 1: Build the adjacency list graph = defaultdict(list) # defaultdict is a subclass of Python’s built-in dict that automatically creates a default value if a key is missing. for u, v in edg..

https://neetcode.io/problems/is-palindrome?list=neetcode150 NeetCode neetcode.io class Solution: def isPalindrome(self, s: str) -> bool: ss = '' for c in s: if c.isalnum(): ss+= c.lower() return ss==ss[::-1]ss = ''Initialize an empty string to store the cleaned version of s.if c.isalnum():isalnum() checks if the character is alphanumeric (letter..

https://neetcode.io/problems/top-k-elements-in-list?list=neetcode150 NeetCode neetcode.io class Solution: def topKFrequent(self, nums: List[int], k: int) -> List[int]: m ={} ans =[] for i in nums: if i in m: m[i]+=1 else: m[i] = 1 l = sorted(m.keys(), key=lambda num: m[num], reverse=True) for u in range(k): ans..

Solution 1. Brute-forceclass Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: for i in range(len(nums)): for j in range(i+1, len(nums)): if nums[i] + nums[j] == target: return [i,j]왜 for j in range(i + 1, len(nums)): 를 쓰나요?twoSum 문제의 기본 아이디어는 모든 가능한 숫자 쌍을 검사해서, 합이 target이 되는 경우를 찾는 거예요. 그런데 중복을 피하고, 자기 자신을 두 번 더하는 걸 방지하..

https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string/ class Solution: def removeDuplicates(self, s: str) -> str: stack = [] for c in s: if stack and stack[-1] == c: stack.pop() else: stack.append(c) return ''.join(stack)

def has_all_unique_characters(s): unique_chars = set(s) if len(s) == len(unique_chars): return True else: return False Using SetsSets are collections of unique elements. You can convert a string into a set to get its unique characters.The order of characters is not guaranteed in a set. text = "programming" unique_chars = set(text) print(unique_chars) # Output: {'g'..