Single linked list solution