solution for the leetcode problem 'reorder the list'