Talentd
FleetCode

423. Reconstruct Original Digits from English

Medium53.4% acceptance4 companies

Given a string s containing an out-of-order English representation of digits 0-9, return the digits in ascending order.

Example 1:

Input: s = "owoztneoer"
Output: "012"

Example 2:

Input: s = "fviefuro"
Output: "45"

Constraints:

  • 1 <= s.length <= 105
  • s[i] is one of the characters ["e","g","f","i","h","o","n","s","r","u","t","w","v","x","z"].
  • s is guaranteed to be valid.

Asked at 4 companies

5:27
Still stuck?Read 3 approaches, or watch a walkthrough.
Open solution
Loading editor…
1class Solution:
2 def originalDigits(self, s: str) -> str:
3
Starter codePython 3Spaces: 4
Examples
Input
"owoztneoer"
Input
"fviefuro"
Your code is saved on this device.Solution