How to solve Leetcode 890. Find and Replace Pattern