Leetcode Problem 3 Solution In Java