java solution for leetcode