@scurrlin/stencil 1.30.3 → 1.30.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +51 -19
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -16,7 +16,7 @@ Whether you are studying for technical interviews, or just starting your coding
16
16
 
17
17
  Most people when they attempt to memorize something study the full text and then attempt to regurgitate it on a blank page. Shocking, I know... but what if there was a step in between? What if memorization and pattern recognition weren't all or nothing games? This is where Stencil comes in.
18
18
 
19
- Stencil is a language-agnostic memorization tool that strips code files down to their first letters while preserving spacing, capitalization, and punctuation. The "stencil" of the file is designed to act as a bridge between having something partially memorized and fully memorized. Below is an example of Stencil in action using LeetCode problem 309 "Best Time to Buy and Sell Stock with Cooldown":
19
+ Stencil is a language-agnostic memorization tool that strips code files down to their first letters while preserving spacing, capitalization, and punctuation. The "stencil" of the file is designed to act as a bridge between having something partially memorized and fully memorized. Below is an example of Stencil in action using LeetCode problem 310 "Minimum Height Trees":
20
20
 
21
21
  ## Example
22
22
 
@@ -24,30 +24,62 @@ Solution
24
24
 
25
25
  ```python
26
26
  class Solution:
27
- def maxProfit(self, prices: List[int]) -> int:
28
- b = -10 ** 9
29
- s = 0
30
- s2 = 0
31
- for i in range(len(prices)):
32
- b = max(b, s2 - prices[i])
33
- s2 = s
34
- s = max(s, b + prices[i])
35
- return s
27
+ def findMinHeightTrees(self, n: int, edges: List[List[int]]) -> List[int]:
28
+ if n == 1 or not edges:
29
+ return [0]
30
+ graph = collections.defaultdict(set)
31
+ ans = []
32
+
33
+ for u, v in edges:
34
+ graph[u].add(v)
35
+ graph[v].add(u)
36
+
37
+ for label, children in graph.items():
38
+ if len(children) == 1:
39
+ ans.append(label)
40
+
41
+ while n > 2:
42
+ n -= len(ans)
43
+ nextLeaves = []
44
+ for leaf in ans:
45
+ u = next(iter(graph[leaf]))
46
+ graph[u].remove(leaf)
47
+ if len(graph[u]) == 1:
48
+ nextLeaves.append(u)
49
+ ans = nextLeaves
50
+
51
+ return ans
36
52
  ```
37
53
 
38
54
  Solution with Stencil
39
55
 
40
56
  ```python
41
57
  c S:
42
- d m(s, p: L[i]) -> i:
43
- b = -1 ** 9
44
- s = 0
45
- s = 0
46
- f i i r(l(p)):
47
- b = m(b, s - p[i])
48
- s = s
49
- s = m(s, b + p[i])
50
- r s
58
+ d f(s, n: i, e: L[L[i]]) -> L[i]:
59
+ i n == 1 o n e:
60
+ r [0]
61
+ g = c.d(s)
62
+ a = []
63
+
64
+ f u, v i e:
65
+ g[u].a(v)
66
+ g[v].a(u)
67
+
68
+ f l, c i g.i():
69
+ i l(c) == 1:
70
+ a.a(l)
71
+
72
+ w n > 2:
73
+ n -= l(a)
74
+ n = []
75
+ f l i a:
76
+ u = n(i(g[l]))
77
+ g[u].r(l)
78
+ i l(g[u]) == 1:
79
+ n.a(u)
80
+ a = n
81
+
82
+ r a
51
83
  ```
52
84
 
53
85
  ## Local Installation
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scurrlin/stencil",
3
- "version": "1.30.3",
3
+ "version": "1.30.4",
4
4
  "description": "A memorization tool that strips code down to first letters and punctuation only.",
5
5
  "main": "src/index.js",
6
6
  "bin": {