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.
Because you are first putting it as head.next which means if it IS null, it will already be at head.next and the return will basically return to the pre-recursion of the last function just to get print a null value
What his code does is, if head.next is null, it will return so that head.data will be printed, otherwise, head=head.next will happen and that will be put into the same function
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Join us
Create a HackerRank account
Be part of a 26 million-strong community of developers
Please signup or login in order to view this challenge
Print in Reverse
You are viewing a single comment's thread. Return to all comments →
this code is similar to yours but it gives a null pointer exception.can you explain why?
Because you are first putting it as head.next which means if it IS null, it will already be at head.next and the return will basically return to the pre-recursion of the last function just to get print a null value
What his code does is, if head.next is null, it will return so that head.data will be printed, otherwise, head=head.next will happen and that will be put into the same function