Java code for of leetcode