Skip to content

Commit fe10012

Browse files
committed
do daily
1 parent 5983247 commit fe10012

File tree

5 files changed

+49
-0
lines changed

5 files changed

+49
-0
lines changed

my-submissions/m2579 v1.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Solution:
2+
def coloredCells(self, n: int) -> int:
3+
return 1 + sum(layer for layer in range(4, n * 4, 4))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Solution:
2+
def coloredCells(self, n: int) -> int:
3+
return 1 + 4 * n // 2 * (n - 1)

my-submissions/m2579.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Notes
2+
3+
```
4+
n output
5+
1 1
6+
2 1 + 4 = 5
7+
3 1 + 4 + 8 = 13
8+
4 1 + 4 + 8 + 12 = 25
9+
5 1 + 4 + 8 + 12 + 16 = 41
10+
```
11+
12+
The difference increases by 4 each time
13+
14+
## V1
15+
16+
Iterative $O(n)$
17+
18+
## V2
19+
20+
Math $O(1)$

my-submissions/m797.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Since the edge is acyclic and directed, we do not have to worry about
2+
going back on our previous nodes

my-submissions/m797.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution:
2+
def _dfs_helper(self, curr: int, n: int, edges: defaultdict, path: List[int] = None, output: List[List[int]] = None) -> List[List[int]] :
3+
if output is None :
4+
output: List[List[int]] = []
5+
6+
if path is None :
7+
path = [curr]
8+
9+
if curr == n - 1 :
10+
output.append(path.copy())
11+
return
12+
13+
for e in edges[curr] :
14+
path.append(e)
15+
self._dfs_helper(e, n, edges, path, output)
16+
path.pop()
17+
18+
return output
19+
20+
def allPathsSourceTarget(self, graph: List[List[int]]) -> List[List[int]]:
21+
return self._dfs_helper(0, len(graph), graph)

0 commit comments

Comments
 (0)