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 ...
随机推荐
- 如何获取App当前版本号
NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary]; NSString *currentVersion = [infoDic ...
- 06MySQL数据库入门
1.数据库的概念 数据库是保存数据的仓库,可以方便的把数据放进去,并且把数据根据各种需求取出来. 数据库管理系统(Database Management System,DBMS)是对数据库进行管理(增 ...
- 关于CenttOS的防火墙问题
Fix “Unit iptables.service failed to load: No such file or directory” Error In CentOS7 最近在升级CentOS7遇 ...
- coreseek(sphinx)错误:WARNING: attribute 'id' not found - IGNORING
coreseek(sphinx)错误:WARNING: attribute 'id' not found - IGNORING原因及解决方法 coreseek(sphinx)建立索引时提示错误: WA ...
- Android 应用层知识纲要
Java基础 * 面向对象 * Java集合框架 * 异常处理 * Java反射, Spring框架,通过反射实现 * 泛型, 静态变成语言 * 文件操作 Android基础 * Activity * ...
- 长期支持版本(即不自动更新版本) - Flash Player 18.0.0.268
无意中发现,适合不喜欢折腾的朋友. 下载链接:(官方:http://www.adobe.com/cn/products/flashplayer/distribution3.html) (分流:http ...
- urlconnection.connect()和url.openconnection()的区别
urlconnect()ion.connect()()方法是抽象的:打开到此 URL 引用的资源的通信链接(如果尚未建立这样的连接). 如果在已打开连接(此时 connect()ed 字段的值为 tr ...
- 最好用的手机编程软件-C4droid
Q:c4droid是什么? A:c4droid(以下简称c4)是安卓平台上最强大的c/c++ 编译器,你可以在手机上用手机编写自己的C/C++程序,并且可以把程序导出成apk文件. 下载地址:http ...
- C# WinForm的SplitContainer控件固定Panel大小[转]
原文地址:http://zhidao.baidu.com/link?url=mhkUszZ8am_vqNX3KAOff-psd3af7Xl3DL77KxJ-rWIAqIArQHzQIEBoX49mQA ...
- Arbitrage
Description Arbitrage is the use of discrepancies in currency exchange rates to transform one unit o ...