Leetcode Problem 8 Solution Java