LeetCode 423. Reconstruct Original Digits from English

Given a non-empty string containing an out-of-order English representation of digits 0-9, output the digits in ascending order.

Note:
Input contains only lowercase English letters.
Input is guaranteed to be valid and can be transformed to its original digits. That means invalid inputs such as “abc” or “zerone” are not permitted.
Input length is less than 50,000.
Example 1:
Input: “owoztneoer”
Output: “012”

Example 2:
Input: “fviefuro”
Output: “45”

题目大意:给一个非空字符串,是一些数字的单词打乱后的顺序,求还原这些数字是哪些以及多少个,按照数字增序排列~

分析:先把0~9这10个数字的字母写出来,就可以知道z、x、w、g、u可以唯一确定0、6、2、8、4的个数,然后按照06284的拼写在别的字母中减去他们的拼写,接下来可以发现按照s、r、o、f、e这样的顺序分别筛出7、3、1、5、9的个数即可~(还有更简洁的代码写法,这样写是为了清晰思路)