Minimum Common Value Leetcode Java