Java Replace First Occurrence Leetcode Problem