How we handle the situation that n is bigger than the length of the linked list?


  • 1

    if we ignore the note,"Given n will always be valid", how we handle the situation that n is bigger than the length of the linked list?


  • 1
    G

    you want do something like n % lengthOfTheList


  • 0
    J

    That depends on the requirement. I think you should confirm that with the person who gives you the problem. "%" is just one way


  • 0
    V

    In the current problem, you can track the 'Next' pointer. If it goes to NULL before it reaches 'n' then just return NULL.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.