Solution to Kth Node from End from Jobdu

7 Aug

Question (in Chinese):

Question Name: Kth Node from End

Question Description: Give an single-linked list, find the Kth last node from the end. If there are less than K nodes in the list, you should return null.

Input: the input might contain multiple test cases. Inside each test case, the first line is two intergers N and K (1 <= N, K <= 1000). N means the size of the list. K means the node to find. The second line includes N integers, as the value of each node in the list.

Output: the value of the node if exist, or “NULL” otherwise.

Be careful to the corner case.

Leave a Reply

Your email address will not be published. Required fields are marked *

Please put your code into a <pre>YOUR CODE</pre> section. Thanks and Happy Coding!