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

Note:

  1. Input contains only lowercase English letters.
  2. 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.
  3. Input length is less than 50,000.

Example 1:

Input: "owoztneoer"

Output: "012"

Example 2:

Input: "fviefuro"

Output: "45"

题意:给出一串乱序的数字单词,输出从小到大排序的对应数字

思路:

  利用暗藏的信息,找出每个数字的英文单词对应的特别的字母,比如two中的w,four中的u,eight中的g,six的x,zero的z,都是唯一的

  three的h,five的f,seven的s出现了两次

  one中的o出现了四次

  nine中的i出现了三次

利用这些特点,把这些字母作为所对应数字的唯一标示进行统计,之后进行数学处理,比如three中的h同时再eight中出现了,那么three的数量减去

eight的数量,就是three的真实数量

C代码如下:

 char* originalDigits(char* s) {
int count[]={};
int i=,j=;
char *str=malloc(sizeof(char)*); //注意只能返回栈空间的变量
while(s[i])
{
if('z'==s[i]) count[]++;
else if ('w'==s[i]) count[]++;
else if ('u'==s[i]) count[]++;
else if ('x'==s[i]) count[]++;
else if ('g'==s[i]) count[]++;
else if ('f'==s[i]) count[]++;
else if ('h'==s[i]) count[]++;
else if ('s'==s[i]) count[]++;
else if ('i'==s[i]) count[]++;
else if ('o'==s[i]) count[]++;
i++;
}
count[]-=count[];
count[]-=count[];
count[]-=count[];
count[]-=(count[]+count[]+count[]);
count[]-=(count[]+count[]+count[]);
for(i=;i<;i++)
{
if(count[i])
while(count[i]--)
{
str[j]=''+i;
j++;
}
}
str[j]='\0';
return str;
}

【LeetCode】423. Reconstruct Original Digits from English的更多相关文章

  1. 【LeetCode】423. Reconstruct Original Digits from English 解题报告(Python)

    [LeetCode]423. Reconstruct Original Digits from English 解题报告(Python) 标签: LeetCode 题目地址:https://leetc ...

  2. [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 ...

  3. 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 ...

  4. 423. Reconstruct Original Digits from English (leetcode)

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

  5. 423. Reconstruct Original Digits from English(Medium)

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

  6. 423 Reconstruct Original Digits from English 从英文中重建数字

    给定一个非空字符串,其中包含字母顺序打乱的英文单词表示的数字0-9.按升序输出原始的数字.注意:    输入只包含小写英文字母.    输入保证合法并可以转换为原始的数字,这意味着像 "ab ...

  7. 423. Reconstruct Original Digits from English

    这个题做得突出一个蠢字.. 思路就是看unique letter,因为题里说肯定是valid string.. 一开始有几个Z就有几个ZERO 同样的还有x for six, g for eight, ...

  8. 【LeetCode】738. Monotone Increasing Digits 解题报告(Python)

    [LeetCode]738. Monotone Increasing Digits 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu ...

  9. 【LeetCode】402. Remove K Digits 解题报告(Python)

    [LeetCode]402. Remove K Digits 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http: ...

随机推荐

  1. SQL server Cannot find one or more

    最近刚安装完sqlserver,新鲜感还没过,却出现了一大堆错误,令人头疼,其中有一个错误:在启动Microsoft SQL Server Management Studio时,出现如下错误提示,程序 ...

  2. js中角度计算

    -. js 关于三角函数算法  弧度 和 角度的理解, 以及相互转换   角的两种单位 度 和 弧      1.弧度的定义       我们知道"度"的定义是,"两条射 ...

  3. oracle_sequence用法

    1.    About Sequences(关于序列) 序列是数据库对象一种.多个用户可以通过序列生成连续的数字以此来实现主键字段的自动.唯一增长,并且一个序列可为多列.多表同时使用.序列消除了串行化 ...

  4. CentOS yum升级GCC到4.8

    wget http://people.centos.org/tru/devtools-2/devtools-2.repo .repo /etc/yum.repos.d --binutils devto ...

  5. Jstatd方式远程监控Linux下 JVM运行情况

    前言 最近一个项目部署在服务器上运行时出现了问题,经过排查发现是java内存溢出的问题,所以为了实时监控服务器java内存的情况,需要远程查看服务器上JVM内存的一些情况.另外服务器系统是CentOS ...

  6. CodeForces 669C Little Artem and Matrix GNU

    模拟. 把操作记录一下,倒着复原回去. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cs ...

  7. Number Sequence (HDU 1711)

    Number Sequence Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  8. IOS Android支持中文与本地文件的读取写入

    转自http://www.xuanyusong.com/archives/1069 和http://www.benmutou.com/archives/2094 前几天有个朋友问我为什么在IOS平台中 ...

  9. html5 -----audio标签

    在现在的公司上班需要做一个html5页面,上下可以滑动的,在页面上需要音乐,默认开始音乐播放,点击音乐标签后音乐停止.后来在项目开发中,遇到性能优化的问题,所以我建议大家以后在使用时不要直接在页面中使 ...

  10. c:set 存值

    <c:forEach items="${appoint}" var="appoint"> <c:set var="begin&quo ...