Skip to content

remove_by_value implementation in singly_linked_list_exercise.py #54

@satadrubasu

Description

@satadrubasu

https://github.com/codebasics/data-structures-algorithms-python/blob/master/data_structures/3_LinkedList/Solution/singly_linked_list_exercise.py

Proposed below :

        if not self.head:
            return

        if self.head.val == value:
            self.head = self.head.next
            return

        itr = self.head
        prev_node = None
        while itr:
            if itr.val == value:
                prev_node.next = itr.next
            prev_node = itr
            itr = itr.next

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions