| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
- array
- dfs
- SQL
- GenerativeAI
- Python
- 파이썬알고리즘
- tree
- Stack
- nlp
- BFS
- stratascratch
- 알고리즘
- Greedy
- 슬라이딩윈도우
- binary Tree
- 코드업
- heap
- 파이썬
- 투포인터
- 생성형AI
- codeup
- LeetCode
- Python3
- graph
- GenAI
- 릿코드
- 리트코드
- two-pointer
- sql코테
- 니트코드
- Today
- Total
목록graph (7)
Tech for good
def count_components(adjacency_dict): # Write your code here visited = set() cnt = 0 def dfs(node): visited.add(node) for neighbor in adjacency_dict[node]: if neighbor not in visited: dfs(neighbor) for node in adjacency_dict: if node not in visited: dfs(node) cnt += 1 return cnt
class Solution: def numIslands(self, grid: List[List[str]]) -> int: n_rows, n_cols = len(grid), len(grid[0]) res = 0 visited = set() def dfs(r, c): visited.add((r,c)) neighbors = [(r-1, c), (r+1, c), (r, c-1), (r, c+1)] # check if visited or not for n_r, n_c in neighbors: if n_r in range(n_rows) and n_c in ..
class Solution: def validPath(self, n: int, edges: List[List[int]], source: int, destination: int) -> bool: # 1. Make a graph ## To figure out neighbor using hash-map ## 0 => [1,2] graph = defaultdict(list) for u, v in edges: graph[u].append(v) graph[v].append(u) # 2. BFS from source q = deque([source]) visited = se..
Properties 1The town judge trusts nobody.Properties 2Everybody (except for the town judge) trusts the town judge.Properties 3There is exactly one person that satisfies properties 1 and 2.class Solution: def findJudge(self, n: int, trust: List[List[int]]) -> int: # To figure out in-degree/out-degree using hash-map in_degree = defaultdict(int) out_degree = defaultdict(int)..
# The knows API is already defined for you.# return a bool, whether a knows b# def knows(a: int, b: int) -> bool:class Solution: def findCelebrity(self, n: int) -> int: # Step 1: Find the celebrity candidate candidate = 0 for i in range(1, n): if knows(candidate, i): # Candidate knows i → candidate is not the celebrity candidate = ..
class Solution: def findJudge(self, n: int, trust: List[List[int]]) -> int: # If there's only one person and no trust relationships, that person is the judge if n == 1 and not trust: return 1 # Initialize trust counts trust_scores = [0] * (n+1) for a,b in trust: trust_scores[a] -= 1 # a trusts someone → cannot be the judge ..
class Solution: def closestMeetingNode(self, edges: List[int], node1: int, node2: int) -> int: def trace_path(start): dist = {} step = 0 while start != -1 and start not in dist: dist[start] = step step += 1 start = edges[start] return dist dist1 = trace_path(node1) dist2 = trace_path(..