All Questions
38 questions
1
vote
0
answers
57
views
Tuple unpacking issue in reversing a linked list using tuple unpacking in Python [duplicate]
Reversing Linked List Leetcode-206
Initial Approach:
class ListNode:
def __init__(self, val=0, next=None):
self.val = val
self.next = next
def reverseList(self, head: Optional[...
-1
votes
1
answer
81
views
AttributeError: 'LinkedList' object has no attribute 'insert_head'
I tried to insert elements in head in a single linkedlist
I don't understand what is wrong with my code. it says:
AttributeError: 'LinkedList' object has no attribute 'insert_head'
Here is my code:
...
0
votes
1
answer
126
views
Find kth node from the end
I written below function to find kth node from the end. However, one hidden test case is failing.
Please let me know what is wrong with below code.
def find_kth_from_end(l, k):
slow = l.head
...
-2
votes
1
answer
114
views
Reversing a linked list in python: What is wrong in my code?
I am trying to reverse a linked list in python. Below is my code which doesn't work (gives an error of 'NoneType' object has no attribute 'next' at the while statement):
class Solution:
def ...
2
votes
1
answer
19
views
How to pass prev_node argument as a Node instance in Linked List insertion method?
I implemented a method to insert an element after a specified node in a Linked List:
class Node:
def __init__(self, data):
self.data = data
self.next = None
class LinkedList:
...
0
votes
2
answers
125
views
Check if the Linked List is Palindrome or not
When I try to check whether the linked list is palindrome or not, the following code gives me the error. My Approach is:
Step 1:- I am reversing the linked list (temp = reverseLL(head).
Step 2:- ...
-1
votes
1
answer
65
views
Reverse the Linked List using Recursion
I am using recursion to reverse the linked list but not getting the result. Whenever I am using the following code for the input [1,2,3,4,5,6,-1], it shows me the result [1->None]. I am not getting ...
-2
votes
1
answer
410
views
1669. Merge In Between Linked Lists - Leetcode - failing test
I am working on the LeetCode problem 1669. Merge In Between Linked Lists:
You are given two linked lists: list1 and list2 of sizes n and m respectively.
Remove list1's nodes from the ath node to the ...
-1
votes
1
answer
128
views
Perform arithmetic on a singly linked list which represent a large number
I have a linked list which represents the large number 2253239487.
class ListNode:
def __init__(self, val, next=None):
self.val = val
self.next = next
def __repr__(self):
...
2
votes
2
answers
50
views
Python linked-list issues of receiving memory addresses when printing unless double calling
I am creating a Linked List implementation and I cannot fix this error of having to double call node.val.val to print the data instead of the memory address.
Here is my implementation:
class ...
0
votes
1
answer
187
views
Merge linked lists from dictionary
I am trying to solve the Merge K sorted lists
Idea behind the solution:
Loop through the list of linkedlists and add each node to the dictionary with the value as key and node as value.
In case of ...
0
votes
1
answer
269
views
How to initialize a LinkedList head to None(as done in C++)?
How to initialize head in this implementation of LinkedList in python?
I know a Node class can be defined that will make things easier.But I am trying to do in this way(like in C++).
class LinkedList:
...
0
votes
2
answers
522
views
my code for linked list is printing address in python
class Node:
def __init__(self, data = None, next = None):
self.data = data
self.next = next
class link:
def __init__(self): ...
2
votes
2
answers
663
views
Merge two linked lists without duplicities
Given two sorted linked lists, where the result should be union without duplicates.
Creating of new nodes is not allowed.
The resulting list will be composed of the elements of the original lists.
...
-2
votes
1
answer
382
views
Singly Linked List Python [closed]
This is the error which is the result of the code that I have run in my terminal
I have some issue with my code, anyone can find the solution of this code?
class Node:
# Node untuk singly ...