Word Pattern Matching Leetcode