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 ...
随机推荐
- 收集 数据库的awr数据,生成报告
该脚本只是把awr报告的内容,原封不动的 展现出来,做记录 awrreport.sql 脚本内容如下: *********************************************** ...
- mysql数据库中编码问题(续)
其实之前的数据库中文乱码问题并没有彻底的解决,虽然在网页上显示正常,但是在数据库中却是乱码,虽然用户看起来没问题,但是自己就遭罪了,而且也是个极大的问题 究其原因,是没注意到一点,就是数据库中表的结构 ...
- Vijos1834 NOI2005 瑰丽华尔兹 动态规划 单调双端队列优化
设dp[t][x][y]表示处理完前t个时间段,钢琴停留在(x,y)处,最多可以走多少个格子 转移时只需逆着当前倾斜的方向统计len个格子(len为时间区间的长度,len=t-s+1),如果遇到障碍就 ...
- java 全角、半角字符串转换
转自:http://www.cnblogs.com/modou/articles/2679815.html 加入了空字符串的验证 半角转全角的方法: /** * @Title: ToSBC * ...
- 手机端QQ客服直接跳转到QQ
企业QQ呼出QQ对话框方法 1.手机端链接是这样的:mqqwpa://im/chat?chat_type=wpa&uin=386807630&version=1&src_typ ...
- Python新手学习基础之初识python——与众不同2
看完了Python的缩进,现在来看看Python的标识符.引号和注释. 标识符 关于Python的标识符,其实不是与众不同,只是有一定的规则. 标识符是编程时使用的名字.在Python中,标识符有几点 ...
- Git error- fatal- Needed a single revision
最近在开发中由于项目结构的重构,有一部分代码被抽出来作为了公共库(git submodule),这样公共库可以独立维护,同时其他库调用它也是非常方便的,避免了到处复制代码的痛苦. 但我在项目重构后第一 ...
- php编译安装configure完全配置够日常所用功能
php编译安装configure完全配置够日常所用功能 ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/p ...
- QBImagePickerController 用法
// // ViewController.m // QBImagePickerControllerDemo // // Created by Tanaka Katsuma on 2013/12/30. ...
- Markdown 测试
量化派业务参考代码 测试二级标题 如果 merchant_id 是外部白条,则执行相关逻辑 if(order.getMerchantId() == Constants.BaitiaoMerchant. ...