【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"
题意:给出一串乱序的数字单词,输出从小到大排序的对应数字
思路:
利用暗藏的信息,找出每个数字的英文单词对应的特别的字母,比如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的更多相关文章
- 【LeetCode】423. Reconstruct Original Digits from English 解题报告(Python)
[LeetCode]423. Reconstruct Original Digits from English 解题报告(Python) 标签: LeetCode 题目地址:https://leetc ...
- [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 ...
- 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 ...
- 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 ...
- 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 ...
- 423 Reconstruct Original Digits from English 从英文中重建数字
给定一个非空字符串,其中包含字母顺序打乱的英文单词表示的数字0-9.按升序输出原始的数字.注意: 输入只包含小写英文字母. 输入保证合法并可以转换为原始的数字,这意味着像 "ab ...
- 423. Reconstruct Original Digits from English
这个题做得突出一个蠢字.. 思路就是看unique letter,因为题里说肯定是valid string.. 一开始有几个Z就有几个ZERO 同样的还有x for six, g for eight, ...
- 【LeetCode】738. Monotone Increasing Digits 解题报告(Python)
[LeetCode]738. Monotone Increasing Digits 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu ...
- 【LeetCode】402. Remove K Digits 解题报告(Python)
[LeetCode]402. Remove K Digits 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http: ...
随机推荐
- How to use dt.Rows.Cast<System.Data.DataRow>().Take(n)
参考文章:http://stackoverflow.com/questions/2787458/how-to-select-top-n-rows-from-a-datatable-dataview-i ...
- git commit
使用 git add 命令将想要快照的内容写入缓存区, 而执行 git commit 将缓存区内容添加到仓库中. Git 为你的每一个提交都记录你的名字与电子邮箱地址,所以第一步需要配置用户名和邮箱地 ...
- nyoj 592 spiral grid(广搜)
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=592 解决以下问题后就方便用广搜解: 1.将数字坐标化,10000坐标为(0,0),这样就 ...
- java 包 修饰符 权限详解
作用域 当前类 同package 子孙类 其他package public √ √ √ √ protected √ √ √ × friendly(default) √ √ × ...
- OBJECT-ORIENTED
- angular学习笔记
1.forEach arr:参数是key,index json:与jquery相反,参数是value,key2.str-->json JSON.parse() ang ...
- js简单固定table表头及css问题分析。
<head> <meta name="viewport" content="width=device-width" /> <tit ...
- [河南省ACM省赛-第三届] BUYING FEED (nyoj 248)
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> us ...
- [转]Delphi中QuotedStr介绍及使用
转自:http://www.360doc.com/content/13/0524/09/7873422_287679198.shtml 使用S:string; qry2.SQL.add('select ...
- schema change + ogg 变更手册
Check OGG until no data queuing in replication process:testRO:a)login test5 –l oggmgrb)oggc)#ggsci ...