isMatch solution for leetcode problem