当前位置:网站首页>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;
}
}
边栏推荐
- The performance and efficiency of the model that can do three segmentation tasks at the same time is better than maskformer! Meta & UIUC proposes a general segmentation model with better performance t
- Reuse of data validation framework Apache bval
- In 2021, the national average salary was released. Have you reached the standard?
- 线程池和单例模式以及文件操作
- Antisamy: a solution against XSS attack tutorial
- 前首富,沉迷种田
- [unity shader] insert pass to realize the X-ray perspective effect of model occlusion
- 手把手教姐姐写消息队列
- 2022-07-04 matlab reads video frames and saves them
- ES6笔记一
猜你喜欢

高温火烧浑不怕,钟薛高想留清白在人间

完整的电商系统

10 schemes to ensure interface data security

【塔望方法论】塔望3W消费战略 - U&A研究法

Nunjuks template engine

CVPR 2022丨学习用于小样本语义分割的非目标知识

将模型的记忆保存下来!Meta&UC Berkeley提出MeMViT,建模时间支持比现有模型长30倍,计算量仅增加4.5%...

静态路由配置

Differences between rip and OSPF and configuration commands

SD_ DATA_ RECEIVE_ SHIFT_ REGISTER
随机推荐
完整的电商系统
Datasimba launched wechat applet, and datanuza accepted the test of the whole scene| StartDT Hackathon
Save the memory of the model! Meta & UC Berkeley proposed memvit. The modeling time support is 30 times longer than the existing model, and the calculation amount is only increased by 4.5%
嵌入式面试题(算法部分)
Idea completely uninstalls installation and configuration notes
Desci: is decentralized science the new trend of Web3.0?
gsap动画库
脑洞从何而来?加州大学最新研究:有创造力的人神经连接会「抄近道」
Redis
2022上半年朋友圈都在传的10本书,找到了
"Decryption" Huawei machine vision Corps: Huawei is moving up and the industry is moving forward
go语言的字符串类型、常量类型和容器类型
Standard ACL and extended ACL
如何给“不卖笔”的晨光估值?
6. About JWT
能同时做三个分割任务的模型,性能和效率优于MaskFormer!Meta&UIUC提出通用分割模型,性能优于任务特定模型!开源!...
单臂路由和三层交换的简单配置
Recommend free online SMS receiving platform in 2022 (domestic and foreign)
标准ACL与扩展ACL
低代码助力企业数字化转型会让程序员失业?