当前位置:网站首页>LeetCode 2325. Decrypt message (map)
LeetCode 2325. Decrypt message (map)
2022-07-19 10:46:00 【Michael Amin】
List of articles
1. subject
Here is the string key and message , Represent an encryption key and an encrypted message respectively .
Decrypt message The steps are as follows :
- Use key in 26 English lowercase letters for the first time The order of occurrence is used as the letter in the replacement table The order .
- Align the replacement table with the common English alphabet , Form a comparison table .
- According to the comparison table Replace message Every letter in .
- Space
' 'remain unchanged .
for example ,key = "happy boy"( The actual encryption key will contain every letter in the alphabet At least once ), Accordingly , You can get some comparison tables ('h' -> 'a'、'a' -> 'b'、'p' -> 'c'、'y' -> 'd'、'b' -> 'e'、'o' -> 'f').
Returns the decrypted message .
Example 1:
Input :key = "the quick brown fox jumps over the lazy dog", message = "vkbs bs t suepuv"
Output :"this is a secret"
explain : The comparison table is shown in the above figure .
extract "the quick brown fox jumps over the lazy dog" The first occurrence of each letter in can get a replacement table .
Example 2:
Input :key = "eljuxhpwnyrdgtqkviszcfmabo", message = "zwx hnfx lqantp mnoeius ycgk vcnjrdb"
Output :"the five boxing wizards jump quickly"
explain : The comparison table is shown in the above figure .
extract "eljuxhpwnyrdgtqkviszcfmabo" The first occurrence of each letter in can get a replacement table .
Tips :
26 <= key.length <= 2000
key From lowercase English letters and ' ' form
key Contains every character in the English alphabet ('a' To 'z') At least once
1 <= message.length <= 2000
message Consists of lowercase letters and ' ' form
source : Power button (LeetCode) link :https://leetcode.cn/problems/decode-the-message
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
2. Problem solving
- Imitate according to the meaning of the topic
class Solution:
def decodeMessage(self, key: str, message: str) -> str:
c = set()
chars = [chr(ord('a')+i) for i in range(26)]
idx = 0
d = {
}
for x in key:
if x not in c and x != ' ':
c.add(x)
d[x] = chars[idx]
idx += 1
return ''.join([d[x] if x in d else x for x in message])
32 ms 15.1 MB Python3
my CSDN Blog address https://michael.blog.csdn.net/
Long click or sweep code pay attention to my official account (Michael amin ), Come on together 、 Learn together !
边栏推荐
- 数据库面基知识汇总后
- 如果是用mybatics去访问达梦数据库,相当于完全一样了?因为SQL语法没变。对吧?
- SAP ABAP CDS view 视图的 Replacement 技术介绍
- 发明闪存能赚多少钱?这是一个日本的狗血故事
- 顺序表的基本建立,以及增删改查的相关操作(c语言描述之顺序表)
- R language uses the aggregate function of epidisplay package to divide numerical variables into different subsets based on factor variables, calculate the summary statistics of each subset, and set na
- LeetCode 2335. 装满杯子需要的最短总时长
- SAP AppGyver 的 Universal Theme System 使用介绍
- 基于“7·20郑州特大暴雨”对空天地一体化通信的思考
- Design and Simulation of intelligent storage cabinet control system
猜你喜欢
随机推荐
如何使用SVG制作沿任意路径排布的文字效果
"Baidu side" angrily sprayed the interviewer! Isn't it that the tree time increases by a line number?
LeetCode 2335. 装满杯子需要的最短总时长
使用tesseract.js-offline识别图片文字记录
R language uses the KAP function of epidisplay package to calculate the proportion of calculation consistency of paired contingency tables and the value of kappa statistics, and uses xtabs function to
【手写数字识别】基于Lenet网络实现手写数字识别附matlab代码
「百度一面」怒喷面试官!不就是树遍历时增加一个行号?
Find balanced binary tree
Autojs learning - multi function treasure chest - medium
开发第一个Flink应用
过拟合与欠拟合
关于hping打流测试工具
VScode+Unity3D的配置
数据库面基知识汇总后
Take a look at this ugly face | MathWorks account unavailable - technical issue
C # treeview tree structure recursive processing (enterprise group type hierarchical tree display)
Analysis and solution of application jar package conflict in yarn environment
String类型函数传递问题
【在vivado中调ila IP核】
ENVI_IDL:使用反距离权重法选取最近n个点插值(底层实现)并输出为Geotiff格式(效果等价于Arcgis中反距离权重插值)









![[Niuke swipe questions] / *c language realizes left-hand rotation of strings*/](/img/74/681975d85a671b4f75f2b392264105.png)