Java version solutions for leetcode