In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
What I want to share with you in this article is about how C++ Leetcode can reconstruct numbers from English. The editor thinks it is very practical, so I share it with you. I hope you can get something after reading this article.
Title
Analysis.
First of all, we analyze the composition of each letter, and then we find that some characters appear in only one word. Let's count the number of these words.
The number of characters in the s string is counted with a hash table, so we can know the number of characters in the s string. Then we pay attention to the characters that only appear in the two numbers.
H only appears in 3Jing 8. Since we already know the number of times 8 appears, we can calculate the number of times 3 appears.
F only appears in 4. 5. Since we already know the number of occurrences of 4, we can calculate the number of occurrences of 5.
S only appears in 6 and 7. Since we already know the number of 6 occurrences, we can calculate the number of 7 occurrences.
At this point, only 1 and 9 are not known, but we already know all the other numbers that contain o, so the remaining number is the number of 1.
Then there are only 9 with I at this time, so just count the number of 9.
After counting the number of times, just arrange them in ascending order.
Code
C++
My code
Class Solution {public: string originalDigits (string s) {unordered_map m; string nums [10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; string res; for (char ch: s) m [ch] + + / / 0 if (m ['z'] > 0) {for (int iTun0; I 0) {int x = m ['w']; for (int iTun0; I 0) {int x = m ['u']; for (int iTun0; I 0) {int x = m ['f'] For (int ionome0; I 0) {int x = m ['x']; for (int iTun0; I 0) {int x = m ['s']; for (int ionome0; I 0) {int x = m ['g']; for (int iTun0) I 0) {int x = m ['o']; for (int iTun0; I 0) {int x = m [t']; for (int iTun0; I 0) {int x = m ['i']; for (int iTun0; I)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.