Java code of leetcode