Skip to content

Commit cdb1fc8

Browse files
committed
Update README.mds
1 parent 546c303 commit cdb1fc8

6 files changed

Lines changed: 55 additions & 30 deletions

File tree

‎.claude/settings.local.json‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"permissions": {
3+
"allow": [
4+
"Bash(grep *)",
5+
"Bash(ls -1 *.py)"
6+
]
7+
}
8+
}

‎arrays/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ Output: `[1,5]`
408408
def arrays_intersection(arr1: List[int], arr2: List[int], arr3: List[int]) -> List[int]:
409409
intersection = set(arr1)
410410
intersection = intersection.intersection(arr2)
411-
return sorted(list(intersection.intersection(arr3)))
411+
return list(intersection.intersection(arr3))
412412
```
413413

414414
```python

‎binary_tree/README.md‎

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ For every odd-indexed level, all nodes at the level have even integer values in
9595
right). Given the root of a binary tree, return true if the binary tree is even odd, otherwise return false.
9696

9797
```python
98-
def even_odd_tree(root: TreeNode):
98+
def even_odd_tree(root: Optional[TreeNode]):
9999
if not root:
100100
return False
101101

@@ -109,14 +109,10 @@ def even_odd_tree(root: TreeNode):
109109
node = level.popleft()
110110

111111
if even:
112-
if node.val % 2 == 0:
113-
return False
114-
if last_value and node.val <= last_value:
112+
if not validate_even(node, last_value):
115113
return False
116114
else:
117-
if node.val % 2 != 0:
118-
return False
119-
if last_value and node.val >= last_value:
115+
if not validate_odd(node, last_value):
120116
return False
121117

122118
last_value = node.val
@@ -128,6 +124,22 @@ def even_odd_tree(root: TreeNode):
128124
even = not even
129125

130126
return True
127+
128+
129+
def validate_even(node: TreeNode, last_value: Optional[int]) -> bool:
130+
if node.val % 2 == 0:
131+
return False
132+
if last_value and node.val <= last_value:
133+
return False
134+
return True
135+
136+
137+
def validate_odd(node: TreeNode, last_value: Optional[int]) -> bool:
138+
if node.val % 2 != 0:
139+
return False
140+
if last_value and node.val >= last_value:
141+
return False
142+
return True
131143
```
132144

133145
## Has Path Sum

‎math_problems/README.md‎

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -81,36 +81,29 @@ Task
8181

8282
Given a year, determine whether it is a leap year. If it is a leap year, return the Boolean True, otherwise return False.
8383

84-
Note that the code stub provided reads from STDIN and passes arguments to the is_leap function. It is only necessary to complete the is_leap function.
85-
8684
Input Format
8785

8886
* the year to test.
8987

9088
Output Format
9189

92-
* The function must return a Boolean value (True/False). Output is handled by the provided code stub.
93-
94-
## Moving Average
95-
96-
Create a class `MovingAverage` to calculate the average of a max amount of numbers (n).
97-
Class should have a `.next(value: int)` method that returns the average after adding the new value.
98-
The oldest values should be removed when adding new values once the max amount of numbers is reached.
90+
* The function must return a Boolean value (True/False).
9991

10092
```python
101-
class MovingAverage:
102-
103-
def __init__(self, max_size: int):
104-
self.max_size = max_size
105-
self.queue = deque()
106-
107-
def next(self, number: int) -> float:
108-
self.queue.append(number)
109-
110-
if len(self.queue) > self.max_size:
111-
self.queue.popleft()
93+
def leap_year(year: int) -> bool:
94+
leap = False
95+
96+
if year % 4 == 0:
97+
if year % 100 == 0 and year % 400 == 0:
98+
leap = True
99+
elif year % 100 == 0:
100+
leap = False
101+
else:
102+
leap = True
103+
else:
104+
leap = False
112105

113-
return sum(self.queue) / float(len(self.queue))
106+
return leap
114107
```
115108

116109
## Power of Three

‎n_ary_tree/README.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ K L
1515
* [Encode Decode](#encode--decode-tree)
1616
* [Level Order Traversal](#level-order-traversal)
1717
* [Max Depth](#max-depth)
18+
* [NaryTreeNode](#narytreenode)
1819
* [Postorder Traversal](#postorder-traversal)
1920
* [Preorder Traversal](#preorder-traversal)
2021

@@ -140,6 +141,17 @@ def max_depth_bottom_up(root: NaryTreeNode) -> int:
140141
return depth
141142
```
142143

144+
## NaryTreeNode
145+
146+
The node class used by all N-ary tree implementations. Each node holds a value and an optional list of child nodes.
147+
148+
```python
149+
class NaryTreeNode:
150+
def __init__(self, value: T, children: Optional[List["NaryTreeNode"]] = None):
151+
self.value: T = value
152+
self.children: Optional[List[NaryTreeNode]] = children
153+
```
154+
143155
## Postorder Traversal
144156

145157
Recursive

‎singly_linked_lists/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* [Intersection Two Linked Lists](#intersection-two-linked-lists)
99
* [Linked List Cycle](#linked-list-cycle)
1010
* [Merge K Sorted Lists](#merge-k-sorted-lists)
11-
* [Merge Two Sorted Lists](#)
11+
* [Merge Two Sorted Lists](#merge-two-sorted-lists)
1212
* [Odd Even Linked List](#odd-even-linked-list)
1313
* [Palindrome Linked List](#palindrome-linked-list)
1414
* [Remove Linked List Elements](#remove-linked-list-elements)

0 commit comments

Comments
 (0)