Leetcode Problem 1 Solution Java