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

思路就是看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. JS实现页面跳转重定向的几种方式

    1.重定向 <script language="javascript"type="text/javascript">  window.locatio ...

  2. 344. Reverse String(C++)

    344. Reverse String Write a function that takes a string as input and returns the string reversed. E ...

  3. jquery获取form表单内容以及绑定数据到form表单

    在日常开发的过程中,难免会用到form表单,我们需要获取表单的数据保存到数据库,或者拿到后台的一串json数据,要将数据绑定到form表单上,这里我写了一个基于jquery的,formHelp插件,使 ...

  4. 通过Java代码浅谈HTTP协议

    最近刚看了http协议,想写点东西加深一下理解,如果哪儿写错了,请指正. 1 介绍 HTTP是Hyper Text Transfer Protocol(超文本传输协议)的缩写.它的发展是万维网协会(W ...

  5. ubuntu更新源

    源一定要找对应的版本 14.04对应 trusty deb http://mirrors.163.com/ubuntu/ trusty main restricted universe multive ...

  6. iPad和iPhone开发的比较

    一.iPad简介 1.什么是iPad 一款苹果公司于2010年发布的平板电脑 定位介于苹果的智能手机iPhone和笔记本电脑产品之间 跟iPhone一样,搭载的是iOS操作系统 2.iPad的市场情况 ...

  7. 无线通信技术协议-6LoWPAN

    6LoWPAN:基于IPv6的低速无线个域网标准,即IPv6 over IEEE 802.15.4. 注:6LoWPAN的协议栈实现在Contiki(完整的一套6LoWPAN协议栈).Zephyr(6 ...

  8. sql 学习之 group by 及 聚合函数

    1.在使用 GROUP BY 子句时,Select列表中的所有列必须是聚合列(SUM,MIN/MAX,AVG等)或是GROUP BY 子句中包括的列.同样,如果在SELECT 列表中使用聚合列,SEL ...

  9. BZOJ 3223 文艺平衡树

    Description   您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作:翻转一个区间,例如原有序序列是5 4 3 2 1,翻转区间是[2,4]的话,结果是5 2  ...

  10. 谈谈react-router学习

    源网页 http://qiutc.me/post/%E8%B0%88%E8%B0%88-react-router.html React + webpack 爽的飞起,少了点什么. 多页面,每次请求页面 ...