Category : linked-list

I’m trying the "add two numbers" (linked list) problem in leetcode. The code that I wrote works fine in Jupyter notebook and returns the correct answer: def list_to_digits(lst): lst.reverse() strings = map(str, lst) a_string = "". join(strings) an_integer = int(a_string) return an_integer def Convert_IntegersToList(integers): res = list(map(int, str(integers))) res.reverse() return(res) class ListNode: def __init__(self, val=0, ..

Read more

I have the following method, and I want to delete {5285831021: ‘Hayes’} from a list. How do I do by just passing 5285831021? class Node: def __init__(self, data=None): self.data = data self.prev = None self.next = None class DoublyLinkedList: def __init__(self): self.head = None self.tail = None def insert(self, pair): if not isinstance(pair, Node): pair ..

Read more

Here is a question from leetcode: Define a function, input the head node of a linked list, invert the linked list. example: input: 1->2->3->4->5->NULL output: 5->4->3->2->1->NULL Here is the official answer to it: # Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.next = next class ..

Read more