We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I don't understand how this is not passing the test. I'm confident it's correct, so much so that I submitted it just to compare it to the solutions on the leaderboard, and even though it failed when I submitted it, it's functionally the same as correct java solutions that were submitted. There's a solution that's exactly like mine except the return is in each conditional. Is this possibly a bug with the system? Help please!
With this code:
Node Insert(Node head,int x) {
Node n = new Node();
n.data = x; n.next = null;
if(head == null) {
head = n;
}
else {
n.next = head;
head = n;
}
return head;
}
I get this:
Your code did not pass this test case.
Insert a node at the head of a linked list
You are viewing a single comment's thread. Return to all comments →
I don't understand how this is not passing the test. I'm confident it's correct, so much so that I submitted it just to compare it to the solutions on the leaderboard, and even though it failed when I submitted it, it's functionally the same as correct java solutions that were submitted. There's a solution that's exactly like mine except the return is in each conditional. Is this possibly a bug with the system? Help please!
With this code:
Node Insert(Node head,int x) { Node n = new Node(); n.data = x; n.next = null; if(head == null) { head = n; } else { n.next = head; head = n; }
return head; }
I get this: Your code did not pass this test case.
Your output: Right Answer!
Compiler Message: Wrong Answer