Java code
The snapshot is from the following problem on leetcode: https://leetcode.com/explore/interview/card/top-interview-questions-easy/93/linked-list/553/