Java Replace First Occurrence Leetcode Python