Update README.md

This commit is contained in:
bt3gl 2023-08-08 20:35:51 -07:00 committed by GitHub
parent 7a42c72a71
commit 454f989928
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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
<br>
```python
def has_cycle(head) -> bool:
@ -72,6 +75,8 @@ def has_cycle(head) -> bool:
return True
```
<br>
----
### 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).
<br>
```python
@ -203,6 +207,8 @@ def remove_kth_node(self, head, n):
### swap every two nodes
<br>
```python
def swap_pairs(head):
@ -218,6 +224,7 @@ def swap_pairs(head):
return second_node
```
<br>
----