890. Find and Replace Pattern Medium
1/**
2 * [890] Find and Replace Pattern
3 *
4 * Given a list of strings words and a string pattern, return a list of words[i] that match pattern. You may return the answer in any order.
5 * A word matches the pattern if there exists a permutation of letters p so that after replacing every letter x in the pattern with p(x), we get the desired word.
6 * 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.
7 *
8 * Example 1:
9 *
10 * Input: words = ["abc","deq","mee","aqq","dkd","ccc"], pattern = "abb"
11 * Output: ["mee","aqq"]
12 * Explanation: "mee" matches the pattern because there is a permutation {a -> m, b -> e, ...}.
13 * "ccc" does not match the pattern because {a -> c, b -> c, ...} is not a permutation, since a and b map to the same letter.
14 *
15 * Example 2:
16 *
17 * Input: words = ["a","b","c"], pattern = "a"
18 * Output: ["a","b","c"]
19 *
20 *
21 * Constraints:
22 *
23 * 1 <= pattern.length <= 20
24 * 1 <= words.length <= 50
25 * words[i].length == pattern.length
26 * pattern and words[i] are lowercase English letters.
27 *
28 */
29pub struct Solution {}
30
31// problem: https://leetcode.com/problems/find-and-replace-pattern/
32// discuss: https://leetcode.com/problems/find-and-replace-pattern/discuss/?currentPage=1&orderBy=most_votes&query=
33
34// submission codes start here
35
36impl Solution {
37 pub fn find_and_replace_pattern(words: Vec<String>, pattern: String) -> Vec<String> {
38 vec![]
39 }
40}
41
42// submission codes end
43
44#[cfg(test)]
45mod tests {
46 use super::*;
47
48 #[test]
49 fn test_890() {
50 }
51}
52
Back
© 2025 bowen.ge All Rights Reserved.