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. (三)Harbor使用OpenLDAP认证登陆

    接上一篇<安装Harbor>,安装好之后,接下来我们使用OpenLDAP来进行Harbor  web界面的登陆验证及权限分配! OpenLDAP: 使用OpenLDAP的都知道,这是一个集 ...

  2. udp接收

    char receive_buffer[500] = {0}; std::vector<std::string> mysplit(std::string str,std::string p ...

  3. Vim编辑器与Shell命令脚本

    章节简述: 本章节将教给您如何使用Vim编辑器来编写文档.配置主机名称.网卡参数以及yum仓库 ,熟练使用各个模式和命令快捷键. 我们可以通过Vim编辑器将Linux命令放入合适的逻辑测试语句(if. ...

  4. Tiny6410之MMU开启

    存储管理单元存储管理单元MMU概述 在ARM系统中,存储管理单元MMU主要完成以下工作:1.虚拟存储空间到物理存储空间的映射.在ARM中采用页式虚拟存储管理.他把虚拟地址空间分成一个个固定大小的块,每 ...

  5. python字符串和列表

    import sys#sys.argv[0] 被设定为指定模块的全名#脚本名和附加参数传入一个名为 sys.argv 的字符串列表.你能够获取这个列表通过执行 import sys,列表的长度大于等于 ...

  6. 在sublime_text3中实现项目的跳转

    作为学习前端的小白,选择了sublime_text3作为学习的编译器.学习的过程是艰辛的,但也是快乐的.遇到自己不会的,有时候会折腾好几个小时,在实现预期效果的时候,那种兴奋真的难以言述. 今天,在学 ...

  7. 在MacOS下Python安装lxml报错xmlversion.h not found 报错的解决方案

    最近在看一个自动化测试框架的问题,需要用到Lxml库,下载lxml总是报错. 1,使用pip安装lxml pip install lxml 2,然后报错了,报错内容是: In file include ...

  8. javsscript总结

  9. linux 启动 关闭 防火墙

    开启防火墙: systemctl start firewalld 关闭防火墙: systemctl stop firewalld

  10. chrome devtools

    Elements chrome devtools 中 Elements panel 是审查 dom 元素和 css 的, 可以实时修改 dom/css. windows: ctrl + shift + ...