diff --git a/linked_lists/README.md b/linked_lists/README.md index 4d8db42..baa9bee 100644 --- a/linked_lists/README.md +++ b/linked_lists/README.md @@ -8,7 +8,8 @@ ```python class Node: - def __init__(self, val=0, next=None): + + def __init__(self, val, next=None): self.val = val self.next = next ``` @@ -52,6 +53,8 @@ class Node: ### detecting cycles +
+ ```python def has_cycle(head) -> bool: @@ -72,6 +75,8 @@ def has_cycle(head) -> bool: return True ``` +
+ ---- ### reversing the list @@ -126,7 +131,6 @@ def delete_node_without_head(node): * however, if the node to be deleted is in the head of the list, the best way is to use a sentinel node. sentinel nodes are widely used in trees and linked lists as pseudo-heads, pseudo-tails, markers of level end, etc. they are purely functional and usually do not hold any data. their main purpose is to standardize the process (by making the list never empty or headless). -
```python @@ -203,6 +207,8 @@ def remove_kth_node(self, head, n): ### swap every two nodes +
+ ```python def swap_pairs(head): @@ -218,6 +224,7 @@ def swap_pairs(head): return second_node ``` +
----