I am wondering for the singly linked list, should I assume there is a header node? Or if I was given an interview about this question, should I confirm that with interviewer?
Because in doubly linked list, I see a more popular implementation will have a header node and a tail node, which do not contain data inside, but just to make code easier to develop.
When in doubt, always confirm. But specifically for the problem for which you have posted this question, its solution does not require an empty header node.
Yes, if a extra header node is used, submitting error will be reported. But why no header node with the standard solution? There is a header node for singly linked list by default actually.
I also found there is a empty header node in a book, but the OJ seems no need to header node. So, maybe in actually programming(working and studying), it is better to add a header node.:D
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.