<jupyter_start><jupyter_text>Delete Node in a Linked ListInput: head = [4,5,1,9], node = 5Output: [4,1,9]Explanation: You are given the second node with value 5, the linked list             should become 4 -> 1 -> 9 after calling your function.Input: head = [4,5,1,9], node = 1Output: [4,5,9]Explanation: You are given the third node with value 1, the linked list             should become 4 -> 5 -> 9 after calling your function.<jupyter_code># Definition for singly-linked list.
# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution:
    def deleteNode(self, node):
        """
        :type node: ListNode
        :rtype: void Do not return anything, modify node in-place instead.
        """
        # Summary: To achieve appearance of deleting the node, we actually need to copy the data for the next node 
        # into the node that we were asked to delete then update the node's pointer to the next nodes pointer value
        
        # Input third node with value 3
        #   {value: 3, pointer: fourth node}

        # Debugging 
        node.val = node.next.val
        #   node.val equals 3
        #   node.next.val equals 4
        #   node.val assigned the value of 4
        # Output
        #   1 -> 2 -> 4 -> 4
        
        node.next = node.next.next
        # node.next = third node 
        # node.next.next = NULL/None
        # node.next assigned NULL/None
        # Output
        #   1 -> 2 -> 4
#Delete alternate node from the list
#Keep track of previous of the node to be deleted. First change the next link of previous node and then free the memory allocated for the node


def deleteNodeAlt(head):
        if not head:
            return None
        
        prev , cur = head, head.next
        while prev and cur :
            #change next link of prev node
            prev.next = cur.next
            #free upcurrent node
            cur = None
            
            #update prev and cur
            prev = prev.next
            if not prev:
                cur = prev.next<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07736117702895111, 'fraction_numerical': 0.0170859041290935, 'mean_word_length': 1.8409703504043127, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '326791', 'license': 'MIT', 'n_tokens_mistral': 598, 'n_tokens_neox': 567, 'n_words': 245, 'path': 'Python/DelNode.ipynb', 'repo_name': 'AlphaTwist/Code-squad', 'size': '2107'}