423. Reconstruct Original Digits from English
这个题做得突出一个蠢字。。
思路就是看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的更多相关文章
- 【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 ...
- 【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 ...
- [LeetCode] Reconstruct Original Digits from English 从英文中重建数字
Given a non-empty string containing an out-of-order English representation of digits 0-9, output the ...
- Leetcode: Reconstruct Original Digits from English
Given a non-empty string containing an out-of-order English representation of digits 0-9, output the ...
随机推荐
- Core Animation系列之CADisplayLink(转)
转自 http://www.tuicool.com/articles/meMVR3 一直以来都想好好学习下CoreAnimation,奈何涉及的东西太多,想要一次性全部搞定时间上不允许,以后会断断续续 ...
- iOS9适配中出现的一些常见问题
本文主要是说一些iOS9适配中出现的坑,如果只是要单纯的了解iOS9新特性可以看瞄神的开发者所需要知道的 iOS 9 SDK 新特性.9月17日凌晨,苹果给用户推送了iOS9正式版,随着有用户陆续升级 ...
- C# div布局
本文讲解使用DIV+CSS布局最基本的内容,读完本文你讲会使用DIV+CSS进行简单的页面布局. 转载请标明:http://www.kwstu.com/ArticleView/divcss_20139 ...
- delegate-使用笔记
public class testclass { public class ProductImages : Page { protected Repeater rptSmallUrls; protec ...
- 原生JS判断密码强弱
前些天工作中有这个需求,自己手写了相关的JS代码,第一种方法是通过ASCII 码判断密码类型,完成用户注册时判断用户输入密码的强度,分强.弱.中三等级,它可以根据用户输入的密码显示对应的密码强弱等级, ...
- python sklearn模型的保存
使用python的机器学习包sklearn的时候,如果训练集是固定的,我们往往想要将一次训练的模型结果保存起来,以便下一次使用,这样能够避免每次运行时都要重新训练模型时的麻烦. 在python里面,有 ...
- 【vc】1_Windows程序内部运行机制
创建一个Win32应用程序步骤: 1.编写WinMain函数; 2.创建窗口(步骤如下): a.设计(一个)窗口类(WNDCLASS) b.注册(该)窗口类. c.创建窗口. d.显示并更新窗口. 3 ...
- 极光推送 api ios参数问题
这是首个app项目,推送用的是极光推送jpush 由于用官方文档出现接收多条的问题,在网上找到一套封装好的,非常感觉这位开发者 //推送.指定人error_reporting(E_ALL^E_NOTI ...
- nginx 环境搭建使用之入门
1.http://nginx.org/下载最新的nginx 现在最新的版本是nginx-1.9.1 下载.tar.gz包 ,解压. timeless@timeless-HP-Pavilion-g4 ...
- IOS各类问题
1.The resource could not be loaded because the App Transport Security policy requires the use of a s ...