Insert a node at the head of a linked list
Insert a node at the head of a linked list
+ 0 comments There are problems with the C# compilation. I suppose the NULLABLE setting should be disabled in project file. And the problem is not only with this task.
Compilation error :(
Check the compiler output, fix the error and try again.
Compile Message
/tmp/submission/20231128/08/54/hackerrank-13c0afafe2e3cf5fd37ee00b3e5a9f6b/code/Solution.cs(32,25): warning CS8625: Cannot convert null literal to non-nullable reference type. [/tmp/submission/20231128/08/54/hackerrank-13c0afafe2e3cf5fd37ee00b3e5a9f6b/code/Solution.csproj]
+ 1 comment Here C# solution have some issue. Same code base from python, is working fine.
Python
def insertNodeAtHead(llist, data): # Write your code here head = SinglyLinkedListNode (data) head.next = llist return head
C#
static SinglyLinkedListNode insertNodeAtHead(SinglyLinkedListNode llist, int data) { var head = new SinglyLinkedListNode(data); head.next = llist; return head; }
+ 0 comments Amazing stuff, could you please let us know how to execute this code. i need it to run for my law site awaiting for your kind response.
+ 0 comments C# code submission always fails as it has -> operator.
/tmp/submission/20231026/22/16/hackerrank-4ca2478418d197f5b158d12e97aa4e5d/code/Solution.cs(85,31): error CS0193: The * or -> operator must be applied to a pointer [/tmp/submission/20231026/22/16/hackerrank-4ca2478418d197f5b158d12e97aa4e5d/code/Solution.csproj]
+ 0 comments Here's a Python 3 code with O(1) time Complexity (Correct me if I'm wrong):
def insertNodeAtHead(llist, data): newNode = SinglyLinkedListNode(data) if llist is None: llist = newNode return llist else: newNode.next = llist llist = newNode return llist
Sort 917 Discussions, By:
Please Login in order to post a comment