Leetcode OJ Question in Java