Are there any way besides counting from the front.


  • 1
    S

    Hi,

    As the question suggests, do you think there is a more efficient way besides counting the length of the list and decide the position of the node to delete from the front?

    Many thanks.


  • 0
    E

    there is. since we're given that n is guaranteed, you know there are at least n nodes in the list; then you walk through the list until a certain condition is met, remove the node, and return the head.


  • 0
    S

    recurse until you hit the tail, then start counting backwards from there, and delete the appropriate node.


Log in to reply
 

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