当前位置:网站首页>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;
}
}
边栏推荐
- NAT地址转换
- Differences between rip and OSPF and configuration commands
- How to choose the appropriate automated testing tools?
- Basic concepts and properties of binary tree
- 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
- App capture of charles+postern
- 线程池的拒绝策略
- A hodgepodge of ICER knowledge points (attached with a large number of topics, which are constantly being updated)
- Nat address translation
- Scientists have observed for the first time that the "electron vortex" helps to design more efficient electronic products
猜你喜欢
[论文分享] Where’s Crypto?
ES6笔记一
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%
Will low code help enterprises' digital transformation make programmers unemployed?
Scientists have observed for the first time that the "electron vortex" helps to design more efficient electronic products
Interview vipshop internship testing post, Tiktok internship testing post [true submission]
二叉树的基本概念和性质
Wechat web debugging 8.0.19 replace the X5 kernel with xweb, so the X5 debugging method can no longer be used. Now there is a solution
持续测试(CT)实战经验分享
如何给“不卖笔”的晨光估值?
随机推荐
Scientists have observed for the first time that the "electron vortex" helps to design more efficient electronic products
Differences between rip and OSPF and configuration commands
The live broadcast reservation channel is open! Unlock the secret of fast launching of audio and video applications
[sword finger offer] 59 - I. maximum value of sliding window
如何选择合适的自动化测试工具?
初识缓存以及ehcache初体验「建议收藏」
AntiSamy:防 XSS 攻击的一种解决方案使用教程
[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
Golang client server login
面试唯品会实习测试岗、抖音实习测试岗【真实投稿】
What is the general yield of financial products in 2022?
DataSimba推出微信小程序,DataNuza接受全场景考验? | StartDT Hackathon
RISCV64
Will domestic software testing be biased
Static routing configuration
How to implement safety practice in software development stage
go语言的字符串类型、常量类型和容器类型
抢占周杰伦
[Tawang methodology] Tawang 3W consumption strategy - U & a research method
【剑指 Offer】59 - I. 滑动窗口的最大值