当前位置:网站首页>leetcode:890. Find and replace mode [two dict records set]
leetcode:890. Find and replace mode [two dict records set]
2022-06-12 06:37:00 【Review of the white speed Dragon King】

analysis
With two dict Record separately word To pattern and pattern To word Mapping
then dict The content is a set, We must make sure that after each update set The length of will not be greater than or equal to 2 Can meet the double shot
ac code
class Solution:
def findAndReplacePattern(self, words: List[str], pattern: str) -> List[str]:
ans = []
m = len(pattern)
for word in words:
myDict1 = defaultdict(set)
myDict2 = defaultdict(set)
flag = True
for i in range(m):
myDict1[pattern[i]].add(word[i])
myDict2[word[i]].add(pattern[i])
if len(myDict1[pattern[i]]) >= 2 or len(myDict2[word[i]]) >= 2:
flag = False
break
if flag:
ans.append(word)
return ans
summary
Understanding of bijection
dict + set application
边栏推荐
- Leetcode January 12 daily question 334 Increasing ternary subsequence
- Computer composition and design work06 - based on MIPS
- platform driver
- Apache POI import export excel file
- Process when solving vagrant up_ builder. rb:43:in `join‘: incompatible character encodings: GBK and UTF-8
- PDF. js FAQs
- 六月集训 第九日——位运算
- [easyexcel] easyexcel checks whether the header matches the tool class encapsulated in easyexcel, including the field verification function. You can use validate to verify
- leetcode:890. 查找和替换模式【两个dict记录双射(set)】
- Modifying theme styles in typora
猜你喜欢

Modifying theme styles in typora

Cv2.fillpoly coco annotator segment coordinate conversion to mask image

丢掉丑陋的 toast,会动的 toast 更有趣

SQL 注入-盲注

Multithreading mode (I) -- protective pause and join source code

QT--实现TCP通信

Leetcode personal question solution (Sword finger offer3-5) 3 Duplicate number in array, 4 Find in 2D array, 5 Replace spaces

Leetcode January 10 daily question 306 Additive number

Bert Chinese classification model training + reasoning + deployment

PHP 读写 COOKIE
随机推荐
Video fire detection based on Gaussian mixture model and multi-color
六月集训 第八日——前缀和
What states do threads have?
GET 和 POST 的区别及留言板代码实现
LeetCode-1078. Bigram participle
LeetCode-1405. Longest happy string
六月集训 第九日——位运算
Redis configuration (IV) -- cluster
LeetCode-1303. Team size
Mastering UI development with unity
LeetCode-1185. Day of the week
[easyexcel] easyexcel checks whether the header matches the tool class encapsulated in easyexcel, including the field verification function. You can use validate to verify
torch在高版本训练的模型在低版本中使用报错
Tomato learning notes -seq2seq
Multithreading (IV) -- no lock (IV) -- unsafe
AI operation ch8
The second day of June training - string
Opencv_100问_第五章 (21-25)
Bert Chinese classification model training + reasoning + deployment
2021 RoboCom 世界机器人开发者大赛-本科组(初赛)