reconstruct-original-digits-from-english(好)
https://leetcode.com/problems/reconstruct-original-digits-from-english/ //https://discuss.leetcode.com/topic/63386/one-pass-o-n-java-solution-simple-and-clear public class Solution {
// zero one two three four five six seven eight nine ten
// z 0
// e 0 1 3 3 5 7 7 8 9
// r 0 3 4
// o 0 1 2 4
// n 1 7 9 9
// t 2 3 8
// w 2
// h 3 8
// f 4 5
// u 4
// i 5 6 8 9
// v 5 7
// s 6 7
// x 6
// g 8 public String originalDigits(String s) {
// 太牛了,开始我也想到统计,但是想到删除字符串那些复杂的操作上面去了 int[] counts = new int[10];
for (int i=0; i<s.length(); i++) {
char ch = s.charAt(i);
if (ch == 'z') counts[0]++;
if (ch == 'u') counts[4]++;
if (ch == 'w') counts[2]++;
if (ch == 'x') counts[6]++;
if (ch == 'g') counts[8]++;
if (ch == 'h') counts[3]++; // 3, 8
if (ch == 's') counts[7]++; // 6, 7
if (ch == 'f') counts[5]++; // 4, 5
if (ch == 'o') counts[1]++; // 0, 1, 2, 4
if (ch == 'i') counts[9]++; // 5, 6, 8, 9
} counts[3] -= counts[8];
counts[7] -= counts[6];
counts[5] -= counts[4];
counts[1] -= counts[0] + counts[2] + counts[4];
counts[9] -= counts[5] + counts[6] + counts[8]; StringBuilder sb = new StringBuilder();
for (int i=0; i<10; i++) {
for (int j=0; j<counts[i]; j++) {
sb.append(i);
}
}
return sb.toString();
}
}
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] 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: 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 ...
- [Swift]LeetCode423. 从英文中重建数字 | 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(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
这个题做得突出一个蠢字.. 思路就是看unique letter,因为题里说肯定是valid string.. 一开始有几个Z就有几个ZERO 同样的还有x for six, g for eight, ...
随机推荐
- 利用BeanUtils工具类封装表单数据
一.BeanUtils工具类的使用 1.首先导入BeanUtils工具类的jar包 commons-beanutils-1.8.0.jar commons-logging-1.1.1.jar 2.se ...
- python_day4学习笔记
一.内置函数
- J2EE MySQL Date数据保持一致解决方案
1.设置MySQL时区,明确指定 MySQL 数据库的时区,不使用引发误解的 CST show variables like '%time_zone%';set global time_zone = ...
- hdu 1243(LCS变形)
反恐训练营 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- 【转】Debug 运行正常,Release版本不能正常运行
http://blog.csdn.net/ruifangcui7758/archive/2010/10/18/5948611.aspx引言 如果在您的开发过程中遇到了常见的错误,或许您的Release ...
- netbeans 开启调试
在URL中加入一个参数 XDEBUG_SESSION_START=netbeans-xdebug
- 链式前向星实现的堆优化dij求最短路模板
#include<cstdio> #include<string> #include<cstdlib> #include<cmath> #include ...
- plsql分支,循环,异常
pl/sql 分支,循环和异常分支: DECLARE BEGIN END; 循环:loop,while,for 1.LOOP EXIT WHEN ...
- 洛谷——P1416 攻击火星
P1416 攻击火星 题目描述 一群外星人将要攻击火星. 火星的地图是一个n个点的无向图.这伙外星人将按照如下方法入侵,先攻击度为0的点(相当于从图中删除掉它),然后是度为1的点,依此类推直到度为n- ...
- [Atcoder Regular Contest 061] Tutorial
Link: ARC061 传送门 C: 暴力$dfs$就好了 #include <bits/stdc++.h> using namespace std; typedef long long ...