-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1309. 解码字母到整数映射.js
More file actions
47 lines (47 loc) · 807 Bytes
/
1309. 解码字母到整数映射.js
File metadata and controls
47 lines (47 loc) · 807 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* @param {string} s
* @return {string}
*/
var freqAlphabets = function (s) {
const map = {
1: "a",
2: "b",
3: "c",
4: "d",
5: "e",
6: "f",
7: "g",
8: "h",
9: "i",
"10#": "j",
"11#": "k",
"12#": "l",
"13#": "m",
"14#": "n",
"15#": "o",
"16#": "p",
"17#": "q",
"18#": "r",
"19#": "s",
"20#": "t",
"21#": "u",
"22#": "v",
"23#": "w",
"24#": "x",
"25#": "y",
"26#": "z",
};
const arr = s.split("#");
const result = [];
for (let i = s.length - 1; i >= 0; i--) {
if (s[i] === "#") {
const temp = s[i - 2] + s[i - 1] + "#";
// console.log()
i -= 2;
result.push(map[temp]);
} else {
result.push(map[s[i]]);
}
}
return result.reverse().join("");
};