@scurrlin/stencil 1.24.0 → 1.24.2
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.
- package/README.md +61 -29
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,48 +16,80 @@ 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
|
|
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 211 "Design Add and Search Words Data Structure":
|
|
20
20
|
|
|
21
21
|
## Example
|
|
22
22
|
|
|
23
23
|
Solution
|
|
24
24
|
|
|
25
25
|
```python
|
|
26
|
-
class
|
|
27
|
-
def
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
for right in range(len(nums)):
|
|
32
|
-
curr_sum += nums[right]
|
|
33
|
-
|
|
34
|
-
while curr_sum >= target:
|
|
35
|
-
if right - left + 1 < min_len:
|
|
36
|
-
min_len = right - left + 1
|
|
37
|
-
curr_sum -= nums[left]
|
|
38
|
-
left += 1
|
|
26
|
+
class TrieNode:
|
|
27
|
+
def __init__(self):
|
|
28
|
+
self.children = {}
|
|
29
|
+
self.is_word = False
|
|
39
30
|
|
|
40
|
-
|
|
31
|
+
class WordDictionary:
|
|
32
|
+
def __init__(self):
|
|
33
|
+
self.root = TrieNode()
|
|
34
|
+
|
|
35
|
+
def addWord(self, word):
|
|
36
|
+
current_node = self.root
|
|
37
|
+
for character in word:
|
|
38
|
+
current_node = current_node.children.setdefault(character, TrieNode())
|
|
39
|
+
current_node.is_word = True
|
|
40
|
+
|
|
41
|
+
def search(self, word):
|
|
42
|
+
def dfs(node, index):
|
|
43
|
+
if index == len(word):
|
|
44
|
+
return node.is_word
|
|
45
|
+
|
|
46
|
+
if word[index] == ".":
|
|
47
|
+
for child in node.children.values():
|
|
48
|
+
if dfs(child, index+1):
|
|
49
|
+
return True
|
|
50
|
+
|
|
51
|
+
if word[index] in node.children:
|
|
52
|
+
return dfs(node.children[word[index]], index+1)
|
|
53
|
+
|
|
54
|
+
return False
|
|
55
|
+
|
|
56
|
+
return dfs(self.root, 0)
|
|
41
57
|
```
|
|
42
58
|
|
|
43
59
|
Solution with Stencil
|
|
44
60
|
|
|
45
61
|
```python
|
|
46
|
-
c
|
|
47
|
-
d
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
62
|
+
c T:
|
|
63
|
+
d __i__(s):
|
|
64
|
+
s.c = {}
|
|
65
|
+
s.i_w = F
|
|
66
|
+
|
|
67
|
+
c W:
|
|
68
|
+
d __i__(s):
|
|
69
|
+
s.r = T()
|
|
70
|
+
|
|
71
|
+
d a(s, w):
|
|
72
|
+
c_n = s.r
|
|
73
|
+
f c i w:
|
|
74
|
+
c_n = c_n.c.s(c, T())
|
|
75
|
+
c_n.i_w = T
|
|
59
76
|
|
|
60
|
-
|
|
77
|
+
d s(s, w):
|
|
78
|
+
d d(n, i):
|
|
79
|
+
i i == l(w):
|
|
80
|
+
r n.i_w
|
|
81
|
+
|
|
82
|
+
i w[i] == ".":
|
|
83
|
+
f c i n.c.v():
|
|
84
|
+
i d(c, i+1):
|
|
85
|
+
r T
|
|
86
|
+
|
|
87
|
+
i w[i] i n.c:
|
|
88
|
+
r d(n.c[w[i]], i+1)
|
|
89
|
+
|
|
90
|
+
r F
|
|
91
|
+
|
|
92
|
+
r d(s.r, 0)
|
|
61
93
|
```
|
|
62
94
|
|
|
63
95
|
## Local Installation
|