Skip to content

Commit bb77f22

Browse files
committed
Add solution #1309
1 parent 421cdf8 commit bb77f22

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* 1309. Decrypt String from Alphabet to Integer Mapping
3+
* https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/
4+
* Difficulty: Easy
5+
*
6+
* Given a string s formed by digits ('0' - '9') and '#' .
7+
* We want to map s to English lowercase characters as follows:
8+
*
9+
* - Characters ('a' to 'i') are represented by ('1' to '9') respectively.
10+
* - Characters ('j' to 'z') are represented by ('10#' to '26#') respectively.
11+
*
12+
* Return the string formed after mapping.
13+
*
14+
* It's guaranteed that a unique mapping will always exist.
15+
*/
16+
17+
/**
18+
* @param {string} s
19+
* @return {string}
20+
*/
21+
var freqAlphabets = function(s) {
22+
return s.replace(/\d{2}#|\d/g, match => {
23+
return String.fromCharCode('a'.charCodeAt() + parseInt(match, 10) - 1);
24+
});
25+
};

0 commit comments

Comments
 (0)