当前位置:网站首页>1805. Number of different integers in the string
1805. Number of different integers in the string
2022-07-06 19:37:00 【Drag is me】
leetcode Force button to brush questions and punch in
subject :1805. The number of different integers in a string
describe : Give you a string word , The string consists of numbers and lowercase letters .
Please replace each character that is not a number with a space . for example ,“a123bc34d8ef34” Will become " 123 34 8 34" . Be careful , The remaining integers are ( Adjacent to each other with at least one space ):“123”、“34”、“8” and “34” .
Return to right word Formed after replacement Different The number of integers .
Only if two integers Without leading zeros The decimal representation of is different , I think these two integers are also different .
Their thinking
1、 Although the title requires that the number of integers be returned , But there is no need to convert strings into integers , Only need statistics to be significant figures ( Don't to 0 The whole number at the beginning ) The number of strings is good ;
2、 Number of different integers , Then set duplicate removal .
Source code ##
class Solution {
public:
int numDifferentIntegers(string word) {
set<string>set;
int flag = 0;
string temp = "";
for (int i = 0; i < word.size(); ++i) {
if (word[i] >= '0' && word[i] <= '9') {
flag = 1;
if (temp == "" && word[i] == '0') continue;
temp += word[i];
} else {
if (flag) {
flag = 0;
set.insert(temp);
temp = "";
}
}
}
if (flag) {
set.insert(temp);
}
return set.size();
}
};
边栏推荐
- Phoenix Architecture 3 - transaction processing
- Actf 2022 came to a successful conclusion, and 0ops team won the second consecutive championship!!
- Solution of commercial supply chain management platform for packaging industry: layout smart supply system and digitally integrate the supply chain of packaging industry
- Spark foundation -scala
- Application of clock wheel in RPC
- Leetcode topic [array] - 119 Yang Hui triangle II
- Unbalance balance (dynamic programming, DP)
- 在解决了 2961 个用户反馈后,我做出了这样的改变...
- MRO industrial products enterprise procurement system: how to refine procurement collaborative management? Industrial products enterprises that want to upgrade must see!
- 121. 买卖股票的最佳时机
猜你喜欢
JDBC详解
理解 YOLOV1 第二篇 预测阶段 非极大值抑制(NMS)
Learning and Exploration - Seamless rotation map
谷粒商城--分布式高级篇P129~P339(完结)
ZABBIX proxy server and ZABBIX SNMP monitoring
An error occurs when installing MySQL: could not create or access the registry key needed for the
Blue Bridge Cup microbial proliferation C language
In depth analysis, Android interview real problem analysis is popular all over the network
Intelligent supply chain management system solution for hardware and electromechanical industry: digital intelligent supply chain "creates new blood" for traditional industries
Dark horse -- redis
随机推荐
LeetCode-1279. 红绿灯路口
算法面试经典100题,Android程序员最新职业规划
中缀表达式转后缀表达式详细思路及代码实现
在解决了 2961 个用户反馈后,我做出了这样的改变...
关于图像的读取及处理等
企业精益管理体系介绍
【计算情与思】扫地僧、打字员、信息恐慌与奥本海默
Help improve the professional quality of safety talents | the first stage of personal ability certification and assessment has been successfully completed!
Swiftui game source code Encyclopedia of Snake game based on geometryreader and preference
Intelligent supply chain management system solution for hardware and electromechanical industry: digital intelligent supply chain "creates new blood" for traditional industries
学习探索-使用伪元素清除浮动元素造成的高度坍塌
CF960G - Bandit Blues(第一类斯特林数+OGF)
Translation D28 (with AC code POJ 26:the nearest number)
1805. 字符串中不同整数的数目
The list of people who passed the fifth phase of personal ability certification assessment was published
Mathematical knowledge -- code implementation of Gaussian elimination (elementary line transformation to solve equations)
Modulenotfounderror: no module named 'PIL' solution
黑马--Redis篇
今日直播 | “人玑协同 未来已来”2022弘玑生态伙伴大会蓄势待发
MySql必知必会学习