Skip to content

Commit 095273b

Browse files
authored
Create 1309-decrypt-string-from-alphabet-to-integer-mapping.js
1 parent 9004782 commit 095273b

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* @param {string} s
3+
* @return {string}
4+
*/
5+
const freqAlphabets = function(s) {
6+
const n = s.length, a = 'a'.charCodeAt(0) - 1
7+
let res = '', cur = '', num = 0
8+
9+
for(let i = n - 1; i >= 0; i--) {
10+
const ch = s[i]
11+
if(cur === '') {
12+
if(ch === '#') {
13+
cur = ch
14+
num = 0
15+
} else{
16+
res = (String.fromCharCode(a + (+ch))) + res
17+
}
18+
} else {
19+
if (num < 1) {
20+
cur = ch + cur
21+
num++
22+
} else {
23+
cur = ch + cur
24+
const tmp = cur.slice(0,cur.length - 1)
25+
res = (String.fromCharCode(a + (+tmp))) + res
26+
cur = ''
27+
num = 0
28+
}
29+
}
30+
}
31+
return res
32+
};

0 commit comments

Comments
 (0)