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. 用js使得输入框input只能输入数字

        JS判断只能是数字和小数点1.文本框只能输入数字代码(小数点也不能输入)<input onkeyup="this.value=this.value.replace(/\D/g, ...

  2. 自己通过centos6.5配置NFS 成功后的笔记,希望对需要的人有点点帮助吧!

         环境介绍:            服务器:centos  172.16.250.170            客户端:centos  172.16.250.172     先用rpm -qa ...

  3. 9.mybatis动态SQL标签的用法

    mybatis动态SQL标签的用法   动态 SQL MyBatis 的强大特性之一便是它的动态 SQL.如果你有使用 JDBC 或其他类似框架的经验,你就能体会到根据不同条件拼接 SQL 语句有多么 ...

  4. Redis安装(CentOS7/tar.gz)

    1. 将安装包redis-3.2.0.tar.gz上传到linux系统,位置随意. 2. 解压文件 .tar.gz 3. 解压后会在当前目录生成文件夹“redis-3.2.0”,将其拷贝到" ...

  5. CountDownLatch使用详解

    正如每个Java文档所描述的那样,CountDownLatch是一个同步工具类,它允许一个或多个线程一直等待,直到其他线程的操作执行完后再执行.在Java并发中,countdownlatch的概念是一 ...

  6. myeclipse的一些优化设置

    注:本文内容复制于little_paper的博客,具体链接为http://little-paper.iteye.com/blog/1670745,感谢little_paper的分享,为便于能随时学习, ...

  7. AndroidStudio0.5.2 BUG 导致 menu 菜单键崩溃

    郁闷了半天,今天发现一点击手机 menu 键应用就崩溃了,记得之前都是好好的,调试了半天代码还是搞不定,于是网上google了一番,发现仅国外有一两篇文章有提到类似问题,据说是 0.5.2 版本的 B ...

  8. RSA算法记录----摘抄

    RSA算法原理(一)   "公钥加密算法". 因为它是计算机通信安全的基石,保证了加密数据不会被破解.你可以想象一下,信用卡交易被破解的后果. 进入正题之前,我先简单介绍一下,什么 ...

  9. C#基础、基础知识点(新人自我总结,开启java学习之路)

    从2016年12月29开班,开课到现在C#基础已经算是简答的学习了一点,一个为期两周的课程,或多或少对现在学的Java有着一定的帮助吧,我们先从软件入门来接触c#这门语言: 一.软件开发中的常用术语: ...

  10. R安装

    linux: 在编译R之前,需要通过yum安装以下几个程序: #yum install gcc-gfortran              #否则报”configure: error: No F77 ...