LeetCode sol in Java