这个题做得突出一个蠢字。。

思路就是看unique letter,因为题里说肯定是valid string。。

一开始有几个Z就有几个ZERO

同样的还有x for six, g for eight, w for two..

比如有x个six,那剩下的i的字母数量要-x,s-=x...

算完0682之后,剩下的数字里所有S都是属于seven的。。

减完之后,剩下所有V都是属于FIVE的。。

顺序有很多种,我是0682754931.

public class Solution
{ public String originalDigits(String str)
{
String res = ""; int[] l = new int[26];
for(int j = 0; j < str.length();j++) l[str.charAt(j) -'a']++; int z = l['z'-'a'];
int e = l['e'-'a'];
int r = l['r'-'a'];
int o = l['o'-'a'];
int n = l['n'-'a'];
int t = l['t'-'a'];
int w = l['w'-'a'];
int h = l['h'-'a'];
int f = l['f'-'a'];
int u = l['u'-'a'];
int i = l['i'-'a'];
int v = l['v'-'a'];
int s = l['s'-'a'];
int x = l['x'-'a'];
int g = l['g'-'a']; int[] nums = new int[10]; // zero
nums[0] = z;
e-=z; r-=z; o-=z; // six
nums[6] = x;
s-=x; i-=x; // eight
nums[8] = g;
e-=g; i-=g;h-=g;t-=g; g-=g; // two
nums[2] = w;
t-=w;o-=w; // seven
nums[7] = s;
s-=nums[7];e-=nums[7]*2;v-=nums[7];n-=nums[7]; // five
nums[5] = v;
f-=nums[5];i-=nums[5];v-=nums[5];e-=nums[5]; // four
nums[4] = f;
f-=nums[4];o-=nums[4];u-=nums[4];r-=nums[4]; // nine
nums[9] = i;
n-=nums[9]*2; i-=nums[9]; e-=nums[9]; // three
nums[3] = t;
t-=nums[3]; h-=nums[3]; r-=nums[3]; e-=nums[3]*2; // one
nums[1] = o; for(int m = 0; m < 10;m++)
{
for(int k = 0; k < nums[m];k++) res+=m;
} return res; } }

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

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

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

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

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

  8. [LeetCode] Reconstruct Original Digits from English 从英文中重建数字

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

  9. Leetcode: Reconstruct Original Digits from English

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

随机推荐

  1. webViewDidFinishLoad 执行多次的问题

    在做网页加载进度条的时候,发现UIWebViewDelegate中webViewDidFinishLoad方法会执行多次: - (void)webViewDidStartLoad:(UIWebView ...

  2. JS 通过系统时间限定 动态添加 select option

    虽然是个简单的效果,还是需要积累一下,记录一下: 在八月一号之后,删除最后一项,新添加2016级 — — 2015级 2014级 2013级 2012级 在六月一号之后,删除最后一项,新添加2016级 ...

  3. javascript——面向对象程序设计(1)

    <script type="text/javascript"> //ECMA-262把对象定义为:“无序属性的 集合,其属性可以包含基本值.对象或者函数” //理解对象 ...

  4. A Script Pro nginx URL重写规则无法播放MP4解决方法

    I am using nginx and I have already add the line location /file/ { rewrite ^/-]+)/([-]+)/([^/]*)/([- ...

  5. Python面向对象OOP

    一 OOP     与C++和Java一样,Python同样具有OOP设计. 过程式:从前到后,一条一条,机器能接受的顺序性方式:方式大概为"首先你应该做什么,第二应该做什么,高级点的做点假 ...

  6. bzoj2096: [Poi2010]Pilots

    Description Tz又耍畸形了!!他要当飞行员,他拿到了一个飞行员测试难度序列,他设定了一个难度差的最大值,在序列中他想找到一个最长的子串,任意两个难度差不会超过他设定的最大值.耍畸形一个人是 ...

  7. Redux1

    Redux 写在前面 写React也有段时间了,一直也是用Redux管理数据流,最近正好有时间分析下源码,一方面希望对Redux有一些理论上的认识:另一方面也学习下框架编程的思维方式. Redux如何 ...

  8. intent.addFlags

     一.Activity和Task(栈)的关系 Task就像一个容器,而Activity就相当与填充这个容器的东西,第一个东西(Activity)则会处于最下面,最后添加的东西(Activity)则会在 ...

  9. ETL控件学习之一从数据库导出数据到平面

    今天主要进行ETL控件的学习.主要是使用微软的SSDT工具.使用DataFlowTask 将数据源导出到目标文件的方式. 1.打开SSDT新建一个SSIS的project,如下图所示: 2.在SSIS ...

  10. RichEdit中插入带背景色文本的一种思路

    uses RichEdit; function TextToRtf( // 将文本处理为RTF格式 mText: WideString // 输入文本 ): WideString; // 返回处理后的 ...