java.lang.Object
g0801_0900.s0890_find_and_replace_pattern.Solution

public class Solution extends Object
890 - Find and Replace Pattern.<p>Medium</p> <p>Given a list of strings <code>words</code> and a string <code>pattern</code>, return <em>a list of</em> <code>words[i]</code> <em>that match</em> <code>pattern</code>. You may return the answer in <strong>any order</strong>.</p> <p>A word matches the pattern if there exists a permutation of letters <code>p</code> so that after replacing every letter <code>x</code> in the pattern with <code>p(x)</code>, we get the desired word.</p> <p>Recall that a permutation of letters is a bijection from letters to letters: every letter maps to another letter, and no two letters map to the same letter.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> words = [&ldquo;abc&rdquo;,&ldquo;deq&rdquo;,&ldquo;mee&rdquo;,&ldquo;aqq&rdquo;,&ldquo;dkd&rdquo;,&ldquo;ccc&rdquo;], pattern = &ldquo;abb&rdquo;</p> <p><strong>Output:</strong> [&ldquo;mee&rdquo;,&ldquo;aqq&rdquo;]</p> <p><strong>Explanation:</strong> &ldquo;mee&rdquo; matches the pattern because there is a permutation {a -> m, b -> e, &hellip;}. &ldquo;ccc&rdquo; does not match the pattern because {a -> c, b -> c, &hellip;} is not a permutation, since a and b map to the same letter.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> words = [&ldquo;a&rdquo;,&ldquo;b&rdquo;,&ldquo;c&rdquo;], pattern = &ldquo;a&rdquo;</p> <p><strong>Output:</strong> [&ldquo;a&rdquo;,&ldquo;b&rdquo;,&ldquo;c&rdquo;]</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= pattern.length <= 20</code></li> <li><code>1 <= words.length <= 50</code></li> <li><code>words[i].length == pattern.length</code></li> <li><code>pattern</code> and <code>words[i]</code> are lowercase English letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details