Java solution for LeetCode problem