@scurrlin/stencil 1.2.9 → 1.3.1

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 +33 -39
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -14,56 +14,50 @@ Whether you are studying for technical interviews, or just starting your coding
14
14
 
15
15
  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.
16
16
 
17
- 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 155 "Min Stack":
17
+ 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 124 "Binary Tree Maximum Path Sum":
18
18
 
19
19
  ## Example
20
20
 
21
21
  Solution
22
22
 
23
23
  ```python
24
- class MinStack:
25
- def __init__(self):
26
- self.stack = []
27
- self.minStack = []
28
-
29
- def push(self, val: int) -> None:
30
- self.stack.append(val)
31
- val = min(val, self.minStack[-1] if self.minStack else val)
32
- self.minStack.append(val)
33
-
34
- def pop(self) -> None:
35
- self.stack.pop()
36
- self.minStack.pop()
37
-
38
- def top(self) -> int:
39
- return self.stack[-1]
40
-
41
- def getMin(self) -> int:
42
- return self.minStack[-1]
24
+ class Solution:
25
+ def maxPathSum(self, root: TreeNode) -> int:
26
+ res = [root.val]
27
+
28
+ def dfs(root):
29
+ if not root:
30
+ return 0
31
+
32
+ leftMax = dfs(root.left)
33
+ rightMax = dfs(root.right)
34
+ leftMax = max(leftMax, 0)
35
+ rightMax = max(rightMax, 0)
36
+ res[0] = max(res[0], root.val + leftMax + rightMax)
37
+ return root.val + max(leftMax, rightMax)
38
+ dfs(root)
39
+ return res[0]
43
40
  ```
44
41
 
45
42
  Solution with Stencil
46
43
 
47
44
  ```python
48
- c M:
49
- d __i__(s):
50
- s.s = []
51
- s.m = []
52
-
53
- d p(s, v: i) -> N:
54
- s.s.a(v)
55
- v = m(v, s.m[-1] i s.m e v)
56
- s.m.a(v)
57
-
58
- d p(s) -> N:
59
- s.s.p()
60
- s.m.p()
61
-
62
- d t(s) -> i:
63
- r s.s[-1]
64
-
65
- d g(s) -> i:
66
- r s.m[-1]
45
+ c S:
46
+ d m(s, r: T) -> i:
47
+ r = [r.v]
48
+
49
+ d d(r):
50
+ i n r:
51
+ r 0
52
+
53
+ l = d(r.l)
54
+ r = d(r.r)
55
+ l = m(l, 0)
56
+ r = m(r, 0)
57
+ r[0] = m(r[0], r.v + l + r)
58
+ r r.v + m(l, r)
59
+ d(r)
60
+ r r[0]
67
61
  ```
68
62
 
69
63
  ## Local Installation
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scurrlin/stencil",
3
- "version": "1.2.9",
3
+ "version": "1.3.1",
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": {