solution for leetcode problem 'Linked list II'