Skip to content

Commit f9fe571

Browse files
committed
Problem done
1 parent f0352bf commit f9fe571

File tree

5 files changed

+43
-3
lines changed

5 files changed

+43
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from collections import defaultdict
2+
from typing import List
3+
4+
5+
class Solution:
6+
"""
7+
Time: O(n)
8+
Memory: O(n)
9+
"""
10+
11+
def countPairs(self, n: int, edges: List[List[int]]) -> int:
12+
def dfs(u: int, visited: set = set()) -> int:
13+
if u in visited:
14+
return 0
15+
visited.add(u)
16+
return 1 + sum(dfs(v) for v in graph[u])
17+
18+
graph = defaultdict(set)
19+
for u, v in edges:
20+
graph[u].add(v)
21+
graph[v].add(u)
22+
23+
return sum(reached * (n - reached) for reached in map(dfs, range(n))) // 2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
"""
6+
Time: O(n)
7+
Memory: O(1)
8+
"""
9+
10+
TYPES = 'PGM'
11+
12+
def garbageCollection(self, garbage: List[str], travel: List[int]) -> int:
13+
last = {c: i for i, grb in enumerate(garbage) for c in grb}
14+
15+
for i in range(1, len(travel)):
16+
travel[i] += travel[i - 1]
17+
18+
return sum(map(len, garbage)) + sum(travel[i - 1] if i > 0 else 0 for c, i in last.items())

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ The repository contains the best versions of my solutions to LeetCode problems
114114
| 2309 | [Greatest English Letter in Upper and Lower Case](https://leetcode.com/problems/greatest-english-letter-in-upper-and-lower-case/) | [Python](Python/Greatest%20English%20Letter%20in%20Upper%20and%20Lower%20Case.py) | $O(1)$ | $O(1)$ | Easy | - |
115115
| 2315 | [Count Asterisks](https://leetcode.com/problems/count-asterisks/) | [Python](Python/Count%20Asterisks.py) | $O(n)$ | $O(1)$ | Easy | - |
116116
| 2331 | [Evaluate Boolean Binary Tree](https://leetcode.com/problems/evaluate-boolean-binary-tree/) | [Python](Python/Evaluate%20Boolean%20Binary%20Tree.py) | $O(n)$ | $O(n)$ | Easy | - |
117-
| 2335 | [Minimum Amount of Time to Fill Cups](https://leetcode.com/problems/minimum-amount-of-time-to-fill-cups/) | [Python](Python/Minimum%20Amount%20of%20Time%20to%20Fill%20Cups.py) | - | - | Easy | - |
118117
| 2341 | [Maximum Number of Pairs in Array](https://leetcode.com/problems/maximum-number-of-pairs-in-array/) | [Python](Python/Maximum%20Number%20of%20Pairs%20in%20Array.py) | $O(n)$ | $O(n)$ | Easy | - |
119118
| 2347 | [Best Poker Hand](https://leetcode.com/problems/best-poker-hand/) | [Python](Python/Best%20Poker%20Hand.py) | $O(1)$ | $O(1)$ | Easy | - |
120119
| 2351 | [First Letter to Appear Twice](https://leetcode.com/problems/first-letter-to-appear-twice/) | [Python](Python/First%20Letter%20to%20Appear%20Twice.py) | $O(n)$ | $O(1)$ | Easy | - |
@@ -135,4 +134,4 @@ The repository contains the best versions of my solutions to LeetCode problems
135134

136135
## Last update
137136

138-
Solution table for problems was generated automatically on 2022-09-10 18:01 +0000
137+
Solution table for problems was generated automatically on 2022-09-10 15:54 +0000

infrastructure/src/parser.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def get_problem_data(cls, title: str) -> Optional[dict]:
2121
return None
2222

2323
if 'errors' in response:
24-
logger.error('Response errors', response['errors'])
24+
logger.error(f'Response errors: {response["errors"]}')
2525
return None
2626

2727
problem_data = response['data']['question']
12 KB
Binary file not shown.

0 commit comments

Comments
 (0)