Description Find the nth to last element of a singly linked list. The minimum number of nodes in list is n. Example Given a List 3->2->1->5->null and n = 2, return node whose value is 1. 解题:给一个链表,求倒数第n个结点的值.先贴一下自己的代码,思路比较简单,遍历两遍,第一遍算结点总数,推出所…
Find the nth to last element of a singly linked list. The minimum number of nodes in list is n. Example Given a List 3->2->1->5->null and n = 2, return node whose value is 1. 分析: 要找到nth to last element,我们需要两个指针,第一个指针先走n步,然后两个指针同时走,知道第一个指针为nu…
Find the nth to last element of a singly linked list. The minimum number of nodes in list is n. Example Given a List ->->->->, . Runner Technique: 两个指针都从Dummy node出发,结束条件是runner.next!=null public class Solution { /** * @param head: The first n…
Yet Another Source Code for LintCode Current Status : 232AC / 289ALL in Language C++, Up to date (2016-02-10) For more problems and solutions, you can see my LintCode repository. I'll keep updating for full summary and better solutions. See cnblogs t…
1.Remove Linked List Elements package linkedlist; /* * Question: Remove all elements from a linked list of integers that have value val. */ public class RemoveLinkedListElements { /** * @param head a ListNode * @param val an integer * @return a ListN…