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. Xcode 注释工具的使用

    1:Xcode 8之后 Goodbye World In Xcode 8, Apple integrated a comment documentation generator plugin, whi ...

  2. session fixation

    转自:session fixation攻击 什么是session fixation攻击 Session fixation有人翻译成"Session完成攻击",实际上fixation ...

  3. PRML 第二章mindmap

    PRML第二章的Mindmap,这一章读的比较快,主要是很多计算和证明的过程都跳过了,感觉不是特别需要认真去看每一个公式,能够记住每个小节的结论.公式就可以了.当然有能力.有时间的人还是可以认真读的, ...

  4. The APR based Apache Tomcat Native library tomcat启动错误

    The APR based Apache Tomcat Native library which allows optimal performance in production environmen ...

  5. ERRO错误解决方案整理

    1.chorm访问本地数据出现跨域问题 Cross origin requests are only supported for protocol schemes: http, data, chrom ...

  6. HDU 5903 Square Distance

    $dp$预处理,贪心. 因为$t$串前半部分和后半部分是一样的,所以只要构造前一半就可以了. 因为要求字典序最小,所以肯定是从第一位开始贪心选择,$a,b,c,d,...z$,一个一个尝试过去,如果发 ...

  7. 使用 Git 报错 error: src refspec master matches more than one.

    今天在使用 Git push 代码时遇到一个报错: error: src refspec master matches more than one. error: failed to push som ...

  8. Chapter 2 Open Book——33

    My chin raised a fraction. 我的下巴抬起来了一点. 我略微抬起下颚. "No, she did not send me here. I sent myself.&q ...

  9. [M]带属性块参照的转换

    有一张表格,表格的每一行都由带有属性的块参照组成,如图: 魔法表格不能直接识别有块参照组成的表格,需要使用 EXPLODE 命令将块参照分解,但多分解带有属性的块只能得到属性的定义 这是就需要使用 B ...

  10. mob.com Android studio 配置环境