Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 3b5a0b1

Browse files
committed
Add solution #423
1 parent ec43b87 commit 3b5a0b1

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* 423. Reconstruct Original Digits from English
3+
* https://leetcode.com/problems/reconstruct-original-digits-from-english/
4+
* Difficulty: Medium
5+
*
6+
* Given a string s containing an out-of-order English representation of digits 0-9,
7+
* return the digits in ascending order.
8+
*/
9+
10+
/**
11+
* @param {string} s
12+
* @return {string}
13+
*/
14+
var originalDigits = function(s) {
15+
const c = new Array(26).fill(0);
16+
const d = new Array(10).fill(0);
17+
18+
for (const char of s) c[char.charCodeAt(0) - 97]++;
19+
20+
[d[0], d[2], d[4], d[6], d[8]] = [c[25], c[22], c[20], c[23], c[6]];
21+
d[3] = c[7] - d[8];
22+
d[5] = c[5] - d[4];
23+
d[7] = c[18] - d[6];
24+
d[1] = c[14] - d[0] - d[2] - d[4];
25+
d[9] = (c[13] - d[1] - d[7]) / 2;
26+
27+
return d.reduce((str, count, i) => str + String(i).repeat(count), '');
28+
};

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@
337337
419|[Battleships in a Board](./0419-battleships-in-a-board.js)|Medium|
338338
420|[Strong Password Checker](./0420-strong-password-checker.js)|Hard|
339339
421|[Maximum XOR of Two Numbers in an Array](./0421-maximum-xor-of-two-numbers-in-an-array.js)|Medium|
340+
423|[Reconstruct Original Digits from English](./0423-reconstruct-original-digits-from-english.js)|Medium|
340341
434|[Number of Segments in a String](./0434-number-of-segments-in-a-string.js)|Easy|
341342
435|[Non-overlapping Intervals](./0435-non-overlapping-intervals.js)|Medium|
342343
437|[Path Sum III](./0437-path-sum-iii.js)|Medium|

0 commit comments

Comments
 (0)