当前位置:网站首页>Leetcode-6108: decrypt messages
Leetcode-6108: decrypt messages
2022-07-05 06:09:00 【Chrysanthemum headed bat】
leetcode-6108: Decrypt the message
subject
Topic linking
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 The order of the first occurrence of English lowercase letters is used to replace the letters in the 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 .
Problem solving
Method 1 : Hashtable
1. By hashing map, Record each letter in key The order in which they first appear , And assign corresponding letters .
2. Space directly skip , Replace letters
class Solution {
public:
string decodeMessage(string key, string message) {
unordered_map<char,char> map;
char c='a';
for(int i=0;i<key.size();i++){
if(key[i]==' ') continue;
if(!map.count(key[i])){
map[key[i]]=c;
c++;
}
}
for(int i=0;i<message.size();i++){
if(message[i]==' ') continue;
char c=message[i];
message[i]=map[c];
}
return message;
}
};
边栏推荐
- Wazuh开源主机安全解决方案的简介与使用体验
- Is it impossible for lamda to wake up?
- Introduction et expérience de wazuh open source host Security Solution
- 【云原生】微服务之Feign自定义配置的记录
- leetcode-6109:知道秘密的人数
- Time of process
- 2020ccpc Qinhuangdao J - Kingdom's power
- 1996. number of weak characters in the game
- How to adjust bugs in general projects ----- take you through the whole process by hand
- Appium foundation - use the first demo of appium
猜你喜欢
开源存储这么香,为何我们还要坚持自研?
1.13 - RISC/CISC
[jailhouse article] jailhouse hypervisor
SPI details
Erreur de connexion Navicat à la base de données Oracle Ora - 28547 ou Ora - 03135
【Jailhouse 文章】Jailhouse Hypervisor
Introduction to LVS [unfinished (semi-finished products)]
Spark中groupByKey() 和 reduceByKey() 和combineByKey()
CF1634 F. Fibonacci Additions
Introduction and experience of wazuh open source host security solution
随机推荐
1996. number of weak characters in the game
[rust notes] 13 iterator (Part 2)
leetcode-1200:最小绝对差
MatrixDB v4.5.0 重磅发布,全新推出 MARS2 存储引擎!
Is it impossible for lamda to wake up?
API related to TCP connection
Typical use cases for knapsacks, queues, and stacks
js快速将json数据转换为url参数
Doing SQL performance optimization is really eye-catching
Simply sort out the types of sockets
leetcode-6108:解密消息
Over fitting and regularization
Codeforces Round #732 (Div. 2) D. AquaMoon and Chess
1.14 - 流水线
LeetCode 1200.最小绝对差
CF1634E Fair Share
Implement a fixed capacity stack
Transform optimization problems into decision-making problems
Matrixdb V4.5.0 was launched with a new mars2 storage engine!
2022 pole technology communication arm virtual hardware accelerates the development of Internet of things software