当前位置:网站首页>LeetCode 890(C#)
LeetCode 890(C#)
2022-07-07 19:05:00 【Just be interesting】
subject
You have a list of words words And a pattern pattern, Do you want to know words Which words in match the pattern .
If there is an arrangement of letters p , Make every letter in the pattern x Replace with p(x) after , We get the words we need , So the words match the patterns .
( Think about it , The arrangement of letters is from letter to letter : Each letter maps to another letter , No two letters map to the same letter .)
return words List of words matching the given pattern in .
You can return the answers in any order .
Example :
Input :words = [“abc”,“deq”,“mee”,“aqq”,“dkd”,“ccc”], pattern = “abb”
Output :[“mee”,“aqq”]
explain :
“mee” Match pattern , Because there are permutations {a -> m, b -> e, …}.
“ccc” Does not match pattern , because {a -> c, b -> c, …} It's not a permutation .
because a and b Map to the same letter .
Code
public class Solution
{
public IList<string> FindAndReplacePattern(string[] words, string pattern)
{
return words.Where(a => Match(a, pattern) && Match(pattern, a)).ToList();
}
private bool Match(string a, string pattern)
{
if (a.Length != pattern.Length) return false;
Dictionary<char, char> dic = new Dictionary<char, char>();
for (int i = 0; i < pattern.Length; i++)
{
(char x, char y) = (pattern[i], a[i]);
if (!dic.ContainsKey(x)) dic.Add(x, y);
else if (dic[x] != y) return false;
}
return true;
}
}
边栏推荐
- Mathematical analysis_ Notes_ Chapter 11: Fourier series
- RISCV64
- 小试牛刀之NunJucks模板引擎
- [information security laws and regulations] review
- 【Unity Shader】插入Pass实现模型遮挡X光透视效果
- The live broadcast reservation channel is open! Unlock the secret of fast launching of audio and video applications
- IP netns command (memo)
- 体总:安全有序恢复线下体育赛事,力争做到国内赛事应办尽办
- [Blue Bridge Cup training 100 questions] sort scratch from small to large. Blue Bridge Cup scratch competition special prediction programming question centralized training simulation exercise question
- [C language] string function
猜你喜欢

RIP和OSPF的区别和配置命令

Calculation of torque target value (ftorque) in servo torque control mode

线程池和单例模式以及文件操作

强化学习-学习笔记8 | Q-learning

Skills of embedded C language program debugging and macro use

idea彻底卸载安装及配置笔记

Mathematical analysis_ Notes_ Chapter 11: Fourier series

Redis

Three forms of multimedia technology commonly used in enterprise exhibition hall design
![Kirk borne's selection of learning resources this week [click the title to download directly]](/img/df/98aa3edf0a70b870684963d52e7c72.png)
Kirk borne's selection of learning resources this week [click the title to download directly]
随机推荐
Complete e-commerce system
Scientists have observed for the first time that the "electron vortex" helps to design more efficient electronic products
标准ACL与扩展ACL
I feel cheated. Wechat tests the function of "size number" internally, and two wechat can be registered with the same mobile number
"Decryption" Huawei machine vision Corps: Huawei is moving up and the industry is moving forward
POJ 1182 :食物链(并查集)[通俗易懂]
ip netns 命令(备忘)
初识缓存以及ehcache初体验「建议收藏」
线程池中的线程工厂
ES6笔记一
国内首次!这家中国企业的语言AI实力被公认全球No.2!仅次于谷歌
2022-07-04 matlab reads video frames and saves them
脑洞从何而来?加州大学最新研究:有创造力的人神经连接会「抄近道」
DeSci:去中心化科学是Web3.0的新趋势?
清华、剑桥、UIC联合推出首个中文事实核查数据集:基于证据、涵盖医疗社会等多个领域
虚拟数字人里的生意经
Three forms of multimedia technology commonly used in enterprise exhibition hall design
行业案例|数字化经营底座助力寿险行业转型
Interview vipshop internship testing post, Tiktok internship testing post [true submission]
Charles+Postern的APP抓包